Is it possible to store a model in a row and use a particular property to display?
Is it possible to store a model in a row and use a particular property to display?
Hi,
Lets say that I have an array filled by objects that look like the following:
[code]
{
id: "22222233333",
attributes:{
name: "John",
lastname: "Peak"
}
}
[/code]
Now lets say that I initialize my datatable like that:
[code]
$("#dt").dataTables({
"sDom": "frtiS",
"sPaginationType": "bootstrap",
"aoColumns": [{ "mDataProp": "name"},{ "mDataProp": "lastname"}],
"bDeferRender": true,
"aaData": arrayOfModel,
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
// aData would be the complete model
}
}
})
[/code]
Id like to display the name and the lastname in my table but I want to be able to access my full model (to use the id...) in the fnRowCallback function.
Is there a way to do that?
Lets say that I have an array filled by objects that look like the following:
[code]
{
id: "22222233333",
attributes:{
name: "John",
lastname: "Peak"
}
}
[/code]
Now lets say that I initialize my datatable like that:
[code]
$("#dt").dataTables({
"sDom": "frtiS",
"sPaginationType": "bootstrap",
"aoColumns": [{ "mDataProp": "name"},{ "mDataProp": "lastname"}],
"bDeferRender": true,
"aaData": arrayOfModel,
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
// aData would be the complete model
}
}
})
[/code]
Id like to display the name and the lastname in my table but I want to be able to access my full model (to use the id...) in the fnRowCallback function.
Is there a way to do that?
This discussion has been closed.
Replies
Allan
Allan, I'm not sure that you understood, my question may not be really clear.
Id like to give the full model to the aaData and to display "model.attributes.name" instead of givin model.attributes to aaData.
That's fine - mDataProp allows dotted object notation - so you could do something like: "mDataProp": "attributes.name" for a column.
This blog post might be of interest: http://datatables.net/blog/Extended_data_source_options_with_DataTables
and this example: http://datatables.net/release-datatables/examples/ajax/deep.html
Allan