Home > DeveloperSection > Forums > How to set the value for corresponding value in jquery data table
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    February-13-2013 1:18 AM

 AJAX AJAX 
Ratings:


 1 Reply(s)
 1285  View(s)
Rate this:

Hi MindStickians!

I create the mvc format data table. But when loading the scriopt its does not match the table data and does not bind in my table row. My code is given

below.

$.ajax({
    // my passing value
    success: function (data) { // i get the data properly
        $('#Table').dataTable().fnClearTable();
        $.each(data, function (k, v) {
            var ID= v.ID;
            var name= v.name;
            var batch= v.batch;

            $('#Table').dataTable().fnAddData([
                ID,
                name,
                batch
            ]);
        });
    }
});


my table:

<table id="Table" width="100%">
    <thead>
        <tr>
            <th>EMP_ID</th>
            <th>EMP_name</th>
            <th>EMP_batch</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

Thanks in advance


 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    February-13-2013 8:00 AM

Hi Marcel!

The key to you problem is the response of your AJAX request. Make sure that it's a proper JSON object composed of an array of objects. Like this:

    {
        "ID": 101,
        "name": "Samual",
        "batch": "A"
    },
    {
        "ID": 102,
        "name": "Denial",
        "batch": "B"
    }


Don't want to miss updates? Please click the below button!

Follow MindStick