fnRender getting error when calling function in it.

fnRender getting error when calling function in it.

tomy300tomy300 Posts: 16Questions: 2Answers: 0
edited September 2013 in DataTables 1.9
Hi all

I'm getting an error DataTables warning (table id = 'grid_ententesClients'): Requested unknown parameter '6' from the data source for row 0

[code]
"aoColumns":[
null,null,null,null,null,null,
{ "fnRender": function (oObj) {
//return oObj.aData[0];
return calculatetax(oObj.aData[0]);

}
},null
],
[/code]

I comment the line "return oObj.aData[0];" , I call function I have create calculatetax, if I use my function I getting this error
if I comment the return calculatetax(oObj.aData[0]); function and uncomment //return oObj.aData[0]; the datatable work just fine.

I tought it's was my function but I did an alert in my function of every parameter and I receive all the data correctly, If I do an alert
of each return in my function I also have all the data.

so I wonder what the bug? the fnRender is rendering too fast ???

thanks

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    What is `calculatetax` returning? If it is null or undefined, then you'd get the error you are seeing. Add `console.log( calculatetax(oObj.aData[0]) )` just before your return to see.

    Also I'd suggest you use mRender rather than fnRender. fnRender is removed in DataTables 1.10 (which is in development).

    Allan
  • tomy300tomy300 Posts: 16Questions: 2Answers: 0
    calculatetax is un function that return tax but it does much more it call jquery ajax and get value from the database, If chose this method instead of modify the current query for the datatable in sAjaxSource it's because I need to join 3 table to get all the data needed.... but if I use this. the datatable query getting bigguer because it use sort and it add AND to my big query and scew the actual query
  • tomy300tomy300 Posts: 16Questions: 2Answers: 0
    console.log( calculatetax(oObj.aData[0]) ) return me what I expect but since calculatetax do database query it take time so the console.log return me number but not in the same order that I send the data, so the fnrender execute too fast for the query,

    it's there a way to pause fnrender until the call is finish?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > it's there a way to pause fnrender until the call is finish?

    Your Ajax call is asynchronous, so you could use the `async` jQuery call to make it synchronous, but that will absolutely kill performance! You really want to find a way of doing the calculation without making an Ajax call. Ideally have the value in the initial data set.

    Allan
  • tomy300tomy300 Posts: 16Questions: 2Answers: 0
    Thanks it's working,

    I may use this method for this project because it don't treat a lot of data at time, but with a lot of data that may cause problem... I tought about fnInitComplete function I could calculate field after initiation ..so I could store in a array oObj.aData[0] and then change the datatable field in fnInitComplete.... but there another problem if the user use pagination.
This discussion has been closed.