Datatables 1.9.1 compatibility issue: Requested unknown parameter

Datatables 1.9.1 compatibility issue: Requested unknown parameter

devpriyadevpriya Posts: 8Questions: 0Answers: 0
edited May 2012 in DataTables 1.9
I am seeing the following message everytime the page loads.

DataTables warning (table id = my-table'): Requested unknown parameter 'iPassPercentage' from the data source for row 0

This wasn't seen in v1.8.

I know why this message is coming, so let me explain the scenario in detail. I am using mDataProp to grab various fields from my JSON object and one of them is passPercentage. I want to render passPercentage in different colors so I wrap it up with a span and return that when I process this field.

Immediately after the passPercentage comes another field for which I need to use the passPercentage again but now the passPercentage field is modified by having span tags around it (I think this was a bad behavior from datatables as it should not modify the original data structure). To workaround this, I appended 'i' infront of all the names in mDataProp. So now even though originally there was no field called as iPassPercentage in my JSON object, the mDataProp will still point to iPassPercentage and inside the processing function I used to use the passPercentage value from the JSON object and wrap it in a span and return it and that value used to get stored in iPassPercentage.

This work around was working fine until I upgraded to v1.9.1 and now this version always complains that the parameter is missing :( I want to know what should be the fix for this? Or have you modified the behavior of datatables that it will not modify the passed JSON object? If this is the case then I can use the original names itself.

--------------------Example------------------------

-- Original data structure (truncated, has more fields) --

myObject = {"passPercentage" : "66.00"}

*********************************************

-- Using without work around code --
"mDataProp":"passPercentage",
"fnRender": function(obj)
{ ...... processing ...... }

-- After processing --
myObject = {"passPercentage" : "66.00"}

*********************************************

-- Workaround code (iPassPercentage doesn't exist in original data structure)--
"mDataProp":"iPassPercentage",
"fnRender": function(obj)
{ ...... processing ...... }


-- After work around, after processing --
myObject = {"passPercentage":"66.00", "iPassPercentage":"66.00"}

This workaround is not working in v1.9.1

Replies

  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    Most likely the reason for this is the use of fnRender without a property being assigned to the column or no default content in its place. fnRender in 1.9 passes in the value of the cell, for which DataTables needs to be able to get the value - hence the issues.

    Can you run your table through the debugger please: http://datatables.net/faqs#unknown_parameter

    Allan
  • devpriyadevpriya Posts: 8Questions: 0Answers: 0
    Hi Allan,

    Thanks for pointing me to sDefaultContent parameter. That solved my problem.

    I want to understand the correct way of doing this -

    Suppose I have pass and fail as two parameters in my JSON data and I want to display the pass percentage in the table instead of either of the two. This is the case where I put "passPercent" as my mDataProp that doesn't exist because if I put either of pass or fail then after the fnRender the value of that parameter gets modified. So what is the recommended way of doing this?

    Thanks,
    Dev
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    I'm not sure I 100% understand I'm afraid, but can you not just use mDataProp: "passPercent" and sDefaultContent for when there was a fail? Otherwise you might need to use fnRender or mDataProp as a function which allows complex data manipulation: http://datatables.net/blog/Orthogonal_data

    Allan
This discussion has been closed.