server-side processing with markup in td
server-side processing with markup in td
I've managed to move to server-side processing for a large data set in my CakePHP app utilizing DataTables. That has been an adventure to say the least. What I've realized now though is I've lost all access to "Helpers" or additional markup in my table cells.
For example:
One cell that shows the name of an object used to render this html:
Object Name
This was easy before changing over to server-side where I don't seem to have as much control of the data rendering. Since several of the cells I have need to render span tags or img tags based on the data I've always mixed-in php processing. Since datatables with a server-side data source is after the fact I'm guessing everything has to be done before the JSON object is passed to the table. Is this correct or am I missing something.
For example:
One cell that shows the name of an object used to render this html:
Object Name
This was easy before changing over to server-side where I don't seem to have as much control of the data rendering. Since several of the cells I have need to render span tags or img tags based on the data I've always mixed-in php processing. Since datatables with a server-side data source is after the fact I'm guessing everything has to be done before the JSON object is passed to the table. Is this correct or am I missing something.
This discussion has been closed.
Replies
You can do it either way. You can either add it to the JSON object before returning it to the client, or you can use the fnRowCallback function. I've tried both, and although my way of thinking worked better letting the server side take care of it, the back-end engineers ultimately decided they didn't want to be the ones to tack on display information into the data model.
It would work either way, though.
If you want to do it on the client side, there are a few recent threads, but here's the general simplified gist:
[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td:eq(6)').wrapInner('');
}
[/code]
What's happening is that for each row, as it's being processed I am getting the column at position 6 (as visible in the DOM; depending on hidden columns may not be the original position in the returned data), and calling jQuery's wrapInner() on it to add an anchor tag with the information (a URL other valid path) found in the ORIGINAL data model at position 7.
Allan's server-side PHP example (sorry, don't have the link offhand) showed how you can add extra information to the returned data. In his example, it conditionally added a strong tag as I recall.