ServerSide with templates for columns
ServerSide with templates for columns
DukeNuken
Posts: 7Questions: 2Answers: 0
Hello.
I am using last version (1.9.4) of datatables and using server side model.
my code you can see here http://freemusiclib.com/Music/Player
[code]
$('#TrackTable').dataTable(
{
"bProcessing": false,
"sAjaxSource": "/Music/ReturnProductTable",
"bServerSide": true,
"bPaginate": true,
"bSort": false,
"aoColumns": [
{ "mData": "Rank" },
{ "mData": "Name" },
{ "mData": "Id"},
{ "mData": "Duration" }
],
"iDisplayLength": 50,
"aoColumnDefs": [
{
//"bSearchable": false,
"aTargets": [0,1,2,3],
"mRender": function ( data, type, row ) {
console.log(data);
console.log(type);
console.log(row);
return data;
}
}]//,
//"iDeferLoading": 1000
});
[/code]
And I need run function for generate advenced table content with html code for each column.
I have few problems:
1) Why I see in debug console.log what each row get called 2 times with type="type" and type="display" ? Why is that? How turn that off?
[code]
50
type
Object {Id: 379314, Rank: 50, Name: "Hammer", Duration: 173}
.......
50
display
Object {Id: 379314, Rank: 50, Name: "Hammer", Duration: 173}
[/code]
2) How I can call to each type of culumn (Rank, Name, Id, Duration) separate function or how I can found out to each type of column called "mRender": function ( data, type, row ) {} ? Because in "data" param came only value, but how get key param?
3) What I should do if in response from server I have like 10 values, but I need generate only 4 columns and use those 10 values for fill controls in those 4 columns by mRender function?
Duke
I am using last version (1.9.4) of datatables and using server side model.
my code you can see here http://freemusiclib.com/Music/Player
[code]
$('#TrackTable').dataTable(
{
"bProcessing": false,
"sAjaxSource": "/Music/ReturnProductTable",
"bServerSide": true,
"bPaginate": true,
"bSort": false,
"aoColumns": [
{ "mData": "Rank" },
{ "mData": "Name" },
{ "mData": "Id"},
{ "mData": "Duration" }
],
"iDisplayLength": 50,
"aoColumnDefs": [
{
//"bSearchable": false,
"aTargets": [0,1,2,3],
"mRender": function ( data, type, row ) {
console.log(data);
console.log(type);
console.log(row);
return data;
}
}]//,
//"iDeferLoading": 1000
});
[/code]
And I need run function for generate advenced table content with html code for each column.
I have few problems:
1) Why I see in debug console.log what each row get called 2 times with type="type" and type="display" ? Why is that? How turn that off?
[code]
50
type
Object {Id: 379314, Rank: 50, Name: "Hammer", Duration: 173}
.......
50
display
Object {Id: 379314, Rank: 50, Name: "Hammer", Duration: 173}
[/code]
2) How I can call to each type of culumn (Rank, Name, Id, Duration) separate function or how I can found out to each type of column called "mRender": function ( data, type, row ) {} ? Because in "data" param came only value, but how get key param?
3) What I should do if in response from server I have like 10 values, but I need generate only 4 columns and use those 10 values for fill controls in those 4 columns by mRender function?
Duke
This discussion has been closed.
Replies
You don't - it is intentionally built that way. You function will be called every time DataTables needs data for that cell, and it might provide different data for each data type (filtering, sorting display etc).
> 2) How I can call to each type of culumn (Rank, Name, Id, Duration) separate function or how I can found out to each type of column called "mRender": function ( data, type, row ) {} ?
Use mData to alter the value that is passed into the function as the first parameter.
> 3) What I should do if in response from server I have like 10 values, but I need generate only 4 columns and use those 10 values for fill controls in those 4 columns by mRender function?
Use the function to generate the data you need from the additional information.
Allan