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:
I have a button to test fnAddData function:
with oSettings is null.
So i must call like this and problem is gone: must ReDraw first.
If anyone fix this bug before, please let me know how to fix without Redraw table?
Thank you very much,
Thanh.
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:
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 += "<a id=\"aEdit" + data + "\" class=\"aAction\" onclick=\"editCategory('" + data + "');\"><i class=\"icon-edit\"></i></a>"; html += " " html += "<a id=\"aDelete" + data + "\" class=\"aAction\" onclick=\"deleteCategory('" + data + "');\"><i class=\"icon-trash\"></i></a>"; return html; } } ] }); showNotify("Load list of Category successfully.", "success"); }
I have a button to test fnAddData function:
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); } });Problem come in fnAddData function in line
var iRow = oSettings.aoData.length;
with oSettings is null.
So i must call like this and problem is gone: must ReDraw first.
oTable.fnDraw(); oTable.fnAddData(newObj);
If anyone fix this bug before, please let me know how to fix without Redraw table?
Thank you very much,
Thanh.