Click here to Skip to main content
15,923,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i am binding my jquery datatable from database.i am getting data in my json object oldDataset variable like

var oldDataset= [
{"aptid":1,"businesname":"skulink","ownrnm":"rajiv"},
{"aptid":2,"businesname":"prodegios","ownrnm":"sanjeev"}
]
but it's not binding in my grid but when i pass static dataset of an array like this format then it binds the table.
var newstring=[
["1","skulink","rajiv"],
["2","prodegios","sanjeev"]
]

so how do i convert my oldDataset like newstring

What I have tried:

JavaScript
$(document).ready(function () {
       $.ajax({
         type: "POST",
         url: "userControls/Wsc_comn.asmx/bindapttable",
         data: "{}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (msg) {

                var data = msg.d;
            $('#example').DataTable({
             data: data,
             columns: [

                 { title: "aptid" },
                 { title: "businesname" },
                 { title: "ownrnm" }

             ]
           });
         }
       });


     });


HTML
<pre><table id="example" class="display" width="100%"></table>


my refrence site is : DataTables example - Javascript sourced data[^]
Posted
Updated 18-Jan-17 22:48pm
v4

1 solution

The data you are getting is in JSON format but the datatable is expecting a simply multi-dimensional array so you need to convert your JSON into an array

JavaScript
var newstring = [];
for(var i = 0; i < oldDataset.length; i++) {
    newstring.push([oldDataset[i].aptid, oldDataset[i].businesname, oldDataset[i].ownrnm]);
}
 
Share this answer
 
Comments
Rajiv.net40 19-Jan-17 5:11am    
it's not giving any output..
F-ES Sitecore 19-Jan-17 5:39am    
So use the debugger to step through and see what's happening\not happening.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900