Render Data from Model

Render Data from Model

bcederbceder Posts: 12Questions: 2Answers: 0

I am trying to render my table data as HTML with data that I am getting on my MVC page model. I keep getting various errors each time I try something different and now it shows nothing. I've done this other places where I am getting data through AJAX, but I need to reuse the data that is already coming into the MVC page.

I am currently getting: Cannot read property 'mData' of undefined

Here is my js code:

 $(document).ready(function () {
        $('#example').DataTable({
            data: messages,
            paging: true,
            ordering: false,
            info: false,
            searching: false,
            pageLength: 1,
            pagingType: 'simple',
            columns: [
                {
                    'data': null,
                    'render': function () {
                        return '<div class="message">'
                            + '<div class="message-header">'
                            + '<h3>Update' + campaign.messages.sequenceNumber + '</h3>'
                            + '</div>'
                            + '<div class="message-posted-by">'
                            + 'Posted by' + campaign.Organizer.FirstName + campaign.Organizer.LastName
                            + '</div>'
                            + '<div class="message-posted-time">'
                            + campaign.messages.addedDateTime.GetRelativeTime()
                            + '</div>'
                            + '<div class="message-text">'
                            + campaign.messages.text
                            + '</div>'
                            + '</div>'
                    }
                }
            ]
        });
    });

Any ideas what I might be missing?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @bceder ,

    That declaration of columns suggests there's only a single column in the table - it should have an entry for each column, not just the one. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.