Server side processing: Put data from different database columns into single dataTables column
Server side processing: Put data from different database columns into single dataTables column
Hi,
I am doing server-side processing and I need to display the returned data so that the data from certain columns is compressed into a single column. So, if my database has columns [ 'name', 'comment', 'timestamp', 'foo', 'bar', 'baz' ] I want to display the name, comment and timestamp values all within the first cell of a row. I've managed to achieve this by using a combination of hidden columns and pre-rendering (using fnRowCallback) - the 'comment' and 'timestamp' columns are hidden, but the data for those columns is rendered under the 'name' column (see the example here: http://live.datatables.net/ataqod/2/edit#source). My question is basically only whether this is the right (or best) way to achieve this.
An obvious solution would be to stuff the relevant values into a single database column, but for various reasons I need to restrict the database entries to just strings. My server-side script simply returns rows, and doesn't do any more complex pre-processing.
Many thanks for any help/suggestions,
Chris
I am doing server-side processing and I need to display the returned data so that the data from certain columns is compressed into a single column. So, if my database has columns [ 'name', 'comment', 'timestamp', 'foo', 'bar', 'baz' ] I want to display the name, comment and timestamp values all within the first cell of a row. I've managed to achieve this by using a combination of hidden columns and pre-rendering (using fnRowCallback) - the 'comment' and 'timestamp' columns are hidden, but the data for those columns is rendered under the 'name' column (see the example here: http://live.datatables.net/ataqod/2/edit#source). My question is basically only whether this is the right (or best) way to achieve this.
An obvious solution would be to stuff the relevant values into a single database column, but for various reasons I need to restrict the database entries to just strings. My server-side script simply returns rows, and doesn't do any more complex pre-processing.
Many thanks for any help/suggestions,
Chris
This discussion has been closed.
Replies
This blog post talks about mData with objects, but it can also be used to reorder arrays - just use a different index: http://datatables.net/blog/Extended_data_source_options_with_DataTables .
Allan
Best,
Christopher
[code]
$(document).ready(function() {
$('#test').dataTable( {
"aaData": [
{
comment: "Lorem ipsum.",
number: 0,
author: "Joe Blogs",
datestamp: "2012-10-17T02:01:32+0000",
foo: 0.0,
bar: 0.9,
baz: 0.4,
quux: -2.3
},
{
comment: "Aliquam erat volutpat.",
number: 1,
author: "Tim Smith",
datestamp: "2012-10-17T07:40:16+0000",
foo: 0.2,
bar: 0.7,
baz: 0.6,
quux: -1.5
}
] ,
"aoColumns": [
{ "mData": "number" },
{ "mData": "comment" },
{ "mData": "foo" },
{ "mData": "bar" },
{ "mData": "baz" },
{ "mData": "quux" }
],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$(nRow).children().eq(1).html(
''+aData.comment+''+aData.author+''+' '+aData.datestamp+'');
}
} );
} );
[/code]