c# - DataTables: Uncaught TypeError: Cannot read property 'length' of undefined? -


so, here ajax call datatables table object. trying json fill in table rows only, has header rows.

i not clear syntax of datatables ajax calls are, differ 1 version other.

$('#maincontentplaceholder_business_return_flights').datatable({     "ajax": {         "url": "browse.aspx/getbusinessflights",         "type": "post",         "contenttype": "application/json; charset=utf-8",         "datatype": "json"     } }); 

i keep getting error: uncaught typeerror: cannot read property 'length' of undefined

here json being returned:

{   "d":{   "draw":"1",   "recordstotal":"70",   "recordsfiltered":"70",   "adata":[              [                 "bi 098",                 "london (lhr)",                 "dubai",                 "08-08-2014",                 "12:55 pm",                 "11:55 pm",                 "royal brunei",                 "1",                 "0",                 "1300",                 "\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectflight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003ebook\u003c/button\u003e"              ],              [                 "cy 383",                 "dubai",                 "larnaca",                 "08-06-2014",                 "1:45 pm",                 "4:05 pm",                 "cyprus airways",                 "1",                 "0",                 "1100",                 "\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectflight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003ebook\u003c/button\u003e"              ]         ]     } } 

update: here return method:

[webmethod] public static dictionary<string, object> getbusinessflights() {     listrows = new list<list<string>>();     business = new table();     economy = new table();      filltable(economy, business, scheduledflights.list);      foreach (tablerow row in business.rows)     {         listrow = new list<string>();          foreach (tablecell cell in row.cells)         {             listrow.add(cell.text);         }          listrows.add(listrow);     }      field = new dictionary<string, object>() { { "draw", "1" }, { "recordstotal", economy.rows.count.tostring() }, { "recordsfiltered", economy.rows.count.tostring() }, { "adata", listrows } };      return field;  } 

note: filltable() fills in data business , economy table objects.

well guess make inroads datatables journey .

datatable filling data :

$('#mydatatable').datatable({             "bprocessing": true,             "bserverside": true,             "sajaxsource": 'dataprovider', // controller action method json return type in turn fills datatable              "bjqueryui": true,             "aocolumns": [                          { "sname": "id"  },                          { "sname": "company_name" },                          { "sname": "address" },                          { "sname": "town" }             ]          }); 

with ajax call means have set :

$.ajax({                         "type": "get",                         "datatype": 'json',                         "contenttype": "application/json; charset=utf-8",                         "url": //source url,                         "data": {},                         "success": function (data) {                             //on success reach                         }                     }); 

your controller return type if sets means works cool :

inside dataprovider action method

return json(new             {                 secho = param.secho, //communication b/w subsequent calls                 itotalrecords = //your count here,                 itotaldisplayrecords = //per page display records count,                 aadata = array list bind datatable             },                         jsonrequestbehavior.allowget); 

ps : when new datatables began these awesome articles move forward . give better idea & sample projects included :

http://www.codeproject.com/articles/155422/jquery-datatables-and-asp-net-mvc-integration-part

regards


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -