Adding name/value pairs to aoData and configuring JSON response before datatables draws the table?
Adding name/value pairs to aoData and configuring JSON response before datatables draws the table?
I'm trying to setup an AJAX "powered" datatables using Coldfusion8 as backend (following this example: http://www.mccran.co.uk/index.cfm/2010/4/29/JQuery-Datatables-plugin-example-using-a-server-side-data-request-coldfusion).
My setup looks like this:
[code]
tblOrders = parameters.table.dataTable( {
"sDom": '<"S"f>t<"E"lpi>',
"bStateSave": true,
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": "form.cfc",
"bJQueryMobileUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bRetrieve": true,
"bCustomFilter":true,
"bLengthChange": true,
"bAutoWidth": false,
"aaSorting": [[ 10, "desc" ]],
"aoColumns": [
{"sName": "box", "bSortable": false },
{"sName": "bestelltyp", "sClass": "jqmSorter"},
{"sName": "erfasst_von", "bSortable": false },
{"sName": "open", "bSortable": false },
{"sName": "status", "sClass": "jqmSorter"},
{"sName": "firma", "sClass": "jqmSorter"},
{"sName": "land", "bSortable": false },
{"sName": "plz", "bSortable": false },
{"sName": "ort", "bSortable": false },
{"sName": "bestellnummer", "bSortable": false },
{"sName": "bestelldatum", "sClass": "jqmSorter"},
{"sName": "gesamtmenge", "bSortable": false },
{"sName": "gesamtsumme", "bSortable": false },
{"sName": "liefdatum", "bSortable": false }
],
"fnHeaderCallback": function( nHead ) { sortableHeaderCells( nHead ) },
"fnInitComplete": function(oSettings, json) { createJQMTable( oSettings, json ) },
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push(
{ "name": "method", "value": "process" },
{ "name": "returnformat", "value": "JSON"}
{ "name": "s_status", "value": $(oSettings.nTable).find('input[name="s_status"]').val() },
{ "name": "form_submitted", "value": $(oSettings.nTable).find('input[name="form_submitted"]').val() },
);
$.ajax({"dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback });
}
[/code]
I have a few question and hope you can give me a hint or two:
- can I add name/value pairs to aoData like this? I need these to route the ajaxCall in Coldfusion
- The actual page is multi-language and I need a hook to grab stuff like "status", which will return (1,2,3,4 or 5) and add the corresponding text info in the correct language. Is there a way to hook into a column or the table before it is displayed? I still have no clue how to add the language texts, but a hook would be a good starting point.
- Anything else you see, that is a no-go?
Thanks!
My setup looks like this:
[code]
tblOrders = parameters.table.dataTable( {
"sDom": '<"S"f>t<"E"lpi>',
"bStateSave": true,
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": "form.cfc",
"bJQueryMobileUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bRetrieve": true,
"bCustomFilter":true,
"bLengthChange": true,
"bAutoWidth": false,
"aaSorting": [[ 10, "desc" ]],
"aoColumns": [
{"sName": "box", "bSortable": false },
{"sName": "bestelltyp", "sClass": "jqmSorter"},
{"sName": "erfasst_von", "bSortable": false },
{"sName": "open", "bSortable": false },
{"sName": "status", "sClass": "jqmSorter"},
{"sName": "firma", "sClass": "jqmSorter"},
{"sName": "land", "bSortable": false },
{"sName": "plz", "bSortable": false },
{"sName": "ort", "bSortable": false },
{"sName": "bestellnummer", "bSortable": false },
{"sName": "bestelldatum", "sClass": "jqmSorter"},
{"sName": "gesamtmenge", "bSortable": false },
{"sName": "gesamtsumme", "bSortable": false },
{"sName": "liefdatum", "bSortable": false }
],
"fnHeaderCallback": function( nHead ) { sortableHeaderCells( nHead ) },
"fnInitComplete": function(oSettings, json) { createJQMTable( oSettings, json ) },
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push(
{ "name": "method", "value": "process" },
{ "name": "returnformat", "value": "JSON"}
{ "name": "s_status", "value": $(oSettings.nTable).find('input[name="s_status"]').val() },
{ "name": "form_submitted", "value": $(oSettings.nTable).find('input[name="form_submitted"]').val() },
);
$.ajax({"dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback });
}
[/code]
I have a few question and hope you can give me a hint or two:
- can I add name/value pairs to aoData like this? I need these to route the ajaxCall in Coldfusion
- The actual page is multi-language and I need a hook to grab stuff like "status", which will return (1,2,3,4 or 5) and add the corresponding text info in the correct language. Is there a way to hook into a column or the table before it is displayed? I still have no clue how to add the language texts, but a hook would be a good starting point.
- Anything else you see, that is a no-go?
Thanks!
This discussion has been closed.
Replies
Yes :-). Typically I would suggest using fnServerParams since you then don't need to write your own $.ajax call, but putting them there is fine.
> - The actual page is multi-language and I need a hook to grab stuff like "status", which will return (1,2,3,4 or 5) and add the corresponding text info in the correct language. Is there a way to hook into a column or the table before it is displayed?
Have a look at fnRender (and in 1.9.3 which is still in development mData, which is like fnRender but better :-) )
> - Anything else you see, that is a no-go?
At I rough guess I think you might want to read over this blog post: http://datatables.net/blog/Extended_data_source_options_with_DataTables . But it might not be needed here.
Allan