oSettings is null when call fnAddData

oSettings is null when call fnAddData

hackthanhhackthanh Posts: 3Questions: 0Answers: 0
edited April 2013 in DataTables 1.9
Dear all,

I'm using DataTables v1.9.4 and facing a problem in Add new Row with .NET MVC3.

In window.onload i called an ajax function to getData and initial dataTable in below:

[code]
var result =
{"Data":{"sEcho":"1","iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[
{"CategoryId":"17","CategoryGuid":"045cd49c-e67f-4c93-9080-ec049412ddf6","CategoryName":null,"CategoryFullName":" Fashion","CategoryDescription":"Fashion Category: Shirt, Skirt, T-shirt, Watch, Accessories...","CategoryParentGuid":"","CategoryParentFullName":""},
{"CategoryId":"18","CategoryGuid":"a82697ea-632f-4642-8b26-4a402ef89d21","CategoryName":null,"CategoryFullName":"- T-shirt","CategoryDescription":"Bubbery, Lacoste, AX, Bay...","CategoryParentGuid":"045cd49c-e67f-4c93-9080-ec049412ddf6","CategoryParentFullName":"Fashion"},{"CategoryId":"28","CategoryGuid":"23f63f81-7a12-4af6-97bb-c4da143fbed4","CategoryName":null,"CategoryFullName":"- Pull","CategoryDescription":"Pull Description","CategoryParentGuid":"045cd49c-e67f-4c93-9080-ec049412ddf6","CategoryParentFullName":"Fashion"}]}};

$('#categoryTable').dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bProcessing": true,
"bDestroy": true,
"bRetrieve": true,
"aaData": result.Data.aaData,
"aoColumns": [
{ "mDataProp": "CategoryFullName",
"bSearchable": false,
"bSortable": false,
"sDefaultContent": ""
},
{
"mDataProp": "CategoryDescription",
"sDefaultContent": ""
},
{
"mDataProp": "CategoryParentFullName",
"sDefaultContent": ""
},
{
"mDataProp": "CategoryGuid",
"bSearchable": false,
"bSortable": false,
"sClass": "center",
"mRender": function (data) {
var html = "";
html += "";
html += " "
html += "";
return html;
}
}
]

});
showNotify("Load list of Category successfully.", "success");
}
[/code]

I have a button to test fnAddData function:
[code]
var newObj = { "CategoryId": "17", "CategoryGuid": "045cd49c-e67f-4c93-9080-ec049412ddf6", "CategoryName": null, "CategoryFullName": " Fashion", "CategoryDescription": "Fashion Category: Shirt, Skirt, T-shirt, Watch, Accessories...", "CategoryParentGuid": "", "CategoryParentFullName": "" };

$("#btnTestAdd").click(function () {

var oTable = $("#tableCategory").dataTable();
if (oTable != null && oTable != "undefined") {
oTable.fnAddData(newObj);
}


});
[/code]
Problem come in fnAddData function in line
[code]var iRow = oSettings.aoData.length;[/code]
with oSettings is null.


So i must call like this and problem is gone: must ReDraw first.
[code]
oTable.fnDraw();
oTable.fnAddData(newObj);
[/code]

If anyone fix this bug before, please let me know how to fix without Redraw table?

Thank you very much,
Thanh.

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    edited April 2013
    Never seen that before. Can you please link to a test page so I can debug the issue: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
  • hackthanhhackthanh Posts: 3Questions: 0Answers: 0
    Dear Allan,

    Thank for your quick response. This is the link of test case, please check it
    http://live.datatables.net/idinat/15/

    Thank you very much.
    Thanh.
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    > $("#tableCategory").dataTable();

    There is no element on the page with the ID `#tableCategory` .

    > if (oTable !== null && oTable != "undefined") {

    If not a valid way of checking if you have any tables in the jQuery object. Use `oTable.length` .

    Allan
  • hackthanhhackthanh Posts: 3Questions: 0Answers: 0
    Oh, That's stupid code! My mistake, sorry for take your time. Thank for your supporting.

    Sorry again :(,
    Thanh.
This discussion has been closed.