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?

LightmanLightman Posts: 4Questions: 0Answers: 0
edited April 2012 in General
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?

Replies

  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    Can't you add the object to the nRow, using $(nRow).data('myDataObject, {"id: "2222233333", ... });?
  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    aData should be complete - is it not? The second parameter to fnRowCallback is just the data source object - the full thin.

    Allan
  • LightmanLightman Posts: 4Questions: 0Answers: 0
    koosvdkolk, I think that this is a good answer, Ill try that. But don't you think that have the full model attached to the DOM AND the modelPart in the aaData at the same time would be a little bit bloated?

    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.
  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    > 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
  • LightmanLightman Posts: 4Questions: 0Answers: 0
    Hoh nice! Keep the good work!!!
This discussion has been closed.