fnRender without mDataProp problem
fnRender without mDataProp problem
grahampcharles
Posts: 20Questions: 1Answers: 0
I'm using fnRender to make "edit" button columns; the data source is an Json object returned from the server, but not filtered there. I let DataTables do all the column defintion:
[code]
oTable = $("#mytable").dataTable({
"bServerSide": false,
"sAjaxSource": "myUrl",
"sServerMethod": "POST",
"aoColumns": [
{ "fnRender": function (o, val) {
return "edit".format(
o.aData['BidderNumber']);
}
},
... ]
});
[/code]
I get the "Requested unknown parameter for column 0" error, but then the table renders absolutely correctly.
Troubleshooting in various ways -- defining the columns explictly, setting "sName" or "sTitle" on the columns -- those didn't help. But I found that the error goes away if I define mDataProp on the column with the fnRender (even though I don't use the value):
[code]
"aoColumns": [
{ "mDataProp": "ColumnIDontUse", "fnRender": function (o, val) {
return "edit".format(
o.aData['BidderNumber']);
}
},
[/code]
I've just started using 1.9 -- I can't say for sure, but I'd say this problem didn't occur in 1.8.x -- I used roughly the same pattern a lot and never found it to be a problem.
I'm not especially worried about this, since it's easy enough to define an mDataProp for every column -- just thought I'd report it.
g.
[code]
oTable = $("#mytable").dataTable({
"bServerSide": false,
"sAjaxSource": "myUrl",
"sServerMethod": "POST",
"aoColumns": [
{ "fnRender": function (o, val) {
return "edit".format(
o.aData['BidderNumber']);
}
},
... ]
});
[/code]
I get the "Requested unknown parameter for column 0" error, but then the table renders absolutely correctly.
Troubleshooting in various ways -- defining the columns explictly, setting "sName" or "sTitle" on the columns -- those didn't help. But I found that the error goes away if I define mDataProp on the column with the fnRender (even though I don't use the value):
[code]
"aoColumns": [
{ "mDataProp": "ColumnIDontUse", "fnRender": function (o, val) {
return "edit".format(
o.aData['BidderNumber']);
}
},
[/code]
I've just started using 1.9 -- I can't say for sure, but I'd say this problem didn't occur in 1.8.x -- I used roughly the same pattern a lot and never found it to be a problem.
I'm not especially worried about this, since it's easy enough to define an mDataProp for every column -- just thought I'd report it.
g.
This discussion has been closed.
Replies
It should be that mDataProp is defined automatically to use the column index for the column that it is operating on, so I don't know where the 'undefined' is coming from in the error message - I would expect an integer to be given - for example: http://live.datatables.net/avujac/edit .
Thinking about the changes since 1.8 - fnRender will now give you the value of the cell as the second property to try and make life easier, so it is trying to read the current cell value, hence the error. So yes, I think you probably could have got away with this in 1.8 - but not in 1.9. I'll think on this a bit to see how it might be improved!
Allan
It's probably relatively common to define a column with "delete, edit" buttons -- what's the preferred method?
In any event, the workaround works fine... so no worries if this is a fringe case.
Same here.
With 1.8.x this worked:
[code]
"aoColumns": [
{ "mDataProp": "alias" },
{ "mDataProp": "user_name" },
{ "mDataProp": "email" },
{ "mDataProp": "groups" },
{ "fnRender": function(o) { return 'fixed value"}}
[/code]
And mDataProp would save it as a integer [4] silently.
In 1.9.1 i get the warning. So i have to write:
[code]
"aoColumns": [
{ "mDataProp": "alias" },
{ "mDataProp": "user_name" },
{ "mDataProp": "email" },
{ "mDataProp": "groups" },
{ "mDataProp": null, "fnRender": function(o) { return 'fixed value"}}
[/code]
No big deal but i think it breaks backwards compatibility a bit. It can be very difficult to guess!!
Allan