Trouble reformatting or rendering column data with mdata, mrender
Trouble reformatting or rendering column data with mdata, mrender
dchevalierCACLV
Posts: 3Questions: 0Answers: 0
Greetings:
I'm having trouble understanding how to use the aoColumns, aTargets, mdata and mrender functions to reformat some column results as links.
I have a table set up with server side processing, and the last two columns (the 6th and 7th column) are configured to return the id (primary key) of the row from the database.
Here is my code the first try:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"aoColumnDefs": [ {
"aTargets": [ 5, 6 ],
"mData": 5,
"mRender": function ( data, type, full ) {
return 'Edit1';
},
"mData": 6,
"mRender": function ( data, type, full ) {
return 'Edit2';
}
}],
"oScroller": {
"loadingIndicator": true
}
} );
} );
[/code]
This results in both the columns I've targeted being set to the same link (the last link) [code] 'Edit2'[/code].
I changed the code to this:
[code]
"aoColumnDefs": [ {
"aTargets": [ 5 ],
"mData": 5,
"mRender": function ( data, type, full ) {
return 'Edit';
},
}],
"aoColumnDefs": [ {
"aTargets": [ 6 ],
"mData": 6,
"mRender": function ( data, type, full ) {
return 'Edit';
}
}],
[/code]
and it completely skips the 6th column but correctly renders the last and 7th column.
I'm not real familiar with javascript, but I've been working with PHP and mysql for about 6 month. What am I doing wrong with this script?
I would be grateful for any assistance.
Best,
David
I'm having trouble understanding how to use the aoColumns, aTargets, mdata and mrender functions to reformat some column results as links.
I have a table set up with server side processing, and the last two columns (the 6th and 7th column) are configured to return the id (primary key) of the row from the database.
Here is my code the first try:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"aoColumnDefs": [ {
"aTargets": [ 5, 6 ],
"mData": 5,
"mRender": function ( data, type, full ) {
return 'Edit1';
},
"mData": 6,
"mRender": function ( data, type, full ) {
return 'Edit2';
}
}],
"oScroller": {
"loadingIndicator": true
}
} );
} );
[/code]
This results in both the columns I've targeted being set to the same link (the last link) [code] 'Edit2'[/code].
I changed the code to this:
[code]
"aoColumnDefs": [ {
"aTargets": [ 5 ],
"mData": 5,
"mRender": function ( data, type, full ) {
return 'Edit';
},
}],
"aoColumnDefs": [ {
"aTargets": [ 6 ],
"mData": 6,
"mRender": function ( data, type, full ) {
return 'Edit';
}
}],
[/code]
and it completely skips the 6th column but correctly renders the last and 7th column.
I'm not real familiar with javascript, but I've been working with PHP and mysql for about 6 month. What am I doing wrong with this script?
I would be grateful for any assistance.
Best,
David
This discussion has been closed.
Replies
[code]
"aoColumnDefs": [
{ 'mRender': function ( data, type, full ) {
return 'Edit';
}, 'aTargets' : [ 5 ] },
{ 'mRender': function ( data, type, full ) {
return 'Edit';
}, 'aTargets' : [ 6 ] },
{ "mData": 5, 'aTargets': [ 5 ] },
{ "mData": 6, 'aTargets': [ 6 ] }
],
[/code]
[code]
var i = 1;
i = 2;
[/code]
and expecting `i` to contain both 1 and 2 :-). Splitting it into two objects is the way to do it:
[code]
"aoColumnDefs": [{
'aTargets': [5],
"mData": 5,
'mRender': function (data, type, full) {
return 'Edit';
}
}, {
'aTargets': [6],
"mData": 6,
'mRender': function (data, type, full) {
return 'Edit';
}
}]
[/code]
Allan