javascript - Having trouble adding row to DataTable -


i building jquery datatable javascript object. table builds fine. then, on user's imput, need add row. having problem. have researched on datatables.net , on so. have read indicates doing should work, doesn't. no row added. here code when datatable initialized.

$("#partslist").datatable({         data: data,         "order": [[1, "asc"]],         "scrolly": "800px",         "scrollcollapse": true,         "paging": false,         columns: [             {stitle: "invtid", data: "invtid", "defaultcontent": '', 'classname': 'invtid'},             {stitle: "line nbr", data: "linenbr", 'classname': 'linenbr', "defaultcontent": 'test'},             {stitle: "bf", data: "bfval", "defaultcontent": ''},             {stitle: "bu", data: "buval", "defaultcontent": ''},             {stitle: "cnvfact", data: "cnvfact"},             {stitle: "origin", data: "origin"},             {stitle: "line tot", data: "linetot"},             {stitle: "description", data: "descr"},             {stitle: "quantity ordered", data: "ordqty"},             {stitle: "quantity ship", data: "qtyship"},             {stitle: "unit", data: "unitdesc"},             {stitle: "sales price", data: "slsprice"},             {stitle: "wood cost", data: "wood"},             {stitle: "treatment cost", data: "treat"},             {stitle: "adjustments", data: "trtadj"},             {stitle: "misc", data: "misc"},             {stitle: "freight", data: "freight"}         ]     }); 

then, after user's input, collecting data. example of data being passed add new row. isn't entire object. trying make sure clear read. fields covered in passing.

object {invtid: "apgc1dbtr061008", bf: 880, bu: 0.88, linenbr: 66536, cnvfact: 0, adj: "-45"bf: 880, freight: "22"} 

and code add new row. passing data method variable name data...

var tbl = $("#partslist").datatable();         tbl.row.add([             data.invtid,             data.linenbr,             data.bf,             data.bu,             data.cnvfact,             data.origin         ]).draw(); 

any reason why isn't working? have tried , tried , searched everywhere , can't find problem.

from doc on row.add():

if data structure used (i.e. array or object) must in same format other data in table (i.e. if table uses objects, pass in object same properties here!).

you'll notice structure doesn't match initial structure in several ways. specifically, start object , try add array, there isn't bf or bu in original table--you have them bfval , buval--and number of properties missing. (i don't know whether add() method fill in missing properties blanks or not; perhaps can try out , see.)

so first, change original table create this:

$("#partslist").datatable({ //etc. 

to this:

var tbl = $("#partslist").datatable({ //etc. 

then rid of this:

var tbl = $("#partslist").datatable(); 

and start this:

tbl.row.add({ //etc. 

and make sure data matches.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -