Auto generated columns content

Auto generated columns content

mariooomariooo Posts: 14Questions: 4Answers: 0

Hi,

I have a problem with auto generated columns content.

In my example I have always 3 columns: guid, businessUnits and node_name.
Other columns content should be auto generated and they source is not in the ajax data source object.

View code:

    <thead>
        <tr>
            <th hidden></th>
            <th hidden></th>
            <th style="width: 400px;">Node name</th>
            @{//each bussiness unit column header
                foreach (var bu in Model.BusinessUnits)
                {
                    <th class="bu-column"><input hidden class="bu_Id" value="@bu.BusinessUnit_ID" />@bu.Code</th>
                }
            }
        </tr>
    </thead>
        columnDefs:[
            { data: "guid", targets: 0 },
            { data: "businessUnits", targets: 1, render: render.businessunits },
            { data: "node_name", targets: 2 },
            { "targets": '_all', "data": null, defaultContent: "<input type ="checkbox" />" }
        ]

I get the Cannot read property 'length' of undefined error.
Do you have any ideas why?

Regards,
Mariusz

Answers

  • allanallan Posts: 46,595Questions: 1Answers: 6,507 Site admin

    My guess is that you are Ajax loading the data and it is empty, but without a link to a test case showing the issue it is impossible to say.

    Allan

  • mariooomariooo Posts: 14Questions: 4Answers: 0

    I have checked the dataSrc function and it correctly loading json object.

    I created a test case for you.

    live.datatables.net/yujiquya/1/edit?html,js,console,output

  • allanallan Posts: 46,595Questions: 1Answers: 6,507 Site admin

    The ajax option is used to specify a location from where Ajax data should be loaded. If you have the data already available, as in your test case, then you should use data to pass that data into DataTables: http://live.datatables.net/yujiquya/2/edit .

    Allan

Sign In or Register to comment.