Help needed extending server side processing with request variables.
Help needed extending server side processing with request variables.
jamesjw007
Posts: 35Questions: 0Answers: 0
I have the table working doing everything correctly with server side processing. Yay!
But, I have a form on the page that the users can select. How can I attach the items the user selects (which should change the information returned).
They can load one of 4 different reports into the table. along with several filters to make the data returned more relevant to what they are looking for.
How would I attach these values to the call that the table uses to get the information?
So for example:
They visit the page and the default report is ran with no filters so it returns everything from the database on that report for that user and throws it into a datatables.
Then they click the build message list button and they select the sponsor report. And add some filters for ranks.
How do I trash the current data (do I need to?) and rerun the report with the new values? Because the data from the default report is no longer relevant since they selected the sponsor report.
But, I have a form on the page that the users can select. How can I attach the items the user selects (which should change the information returned).
They can load one of 4 different reports into the table. along with several filters to make the data returned more relevant to what they are looking for.
How would I attach these values to the call that the table uses to get the information?
So for example:
They visit the page and the default report is ran with no filters so it returns everything from the database on that report for that user and throws it into a datatables.
Then they click the build message list button and they select the sponsor report. And add some filters for ranks.
How do I trash the current data (do I need to?) and rerun the report with the new values? Because the data from the default report is no longer relevant since they selected the sponsor report.
This discussion has been closed.
Replies
Use the fnServerParams option to add extra parameters to the data that gets sent to the server. Demo: http://datatables.net/release-datatables/examples/server_side/custom_vars.html
Allan
I created a button for the user the click that loads up the option to change the report and add filters. Once they have done all of that they click a button called #GenerateList. Is it possible to use data tables to rebuild the table with the new parameters without doing a page refresh?
Example:
Table loads with default info
User clicks #buildMsgList
User changes report
User adds filter
User clicks #GenerateList (modal vanishes)
Table is reloaded with new parameters. I'm sure you have a demo here somewhere for what I am trying to do, just not sure where it is. =(
Use fnServerParams
[code]
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "filter_data", "value": formData } );
}
[/code]
When the user clicks the filter button I serialize the data and assign it to the formData variable.
[code]
$('#filterButton').click(function () {
formData = $('#my_form').serialize();
oTable.fnDraw();
});
[/code]
Then on the server side I extract the required data and process my query.
[code]
var oTable = jQuery('#dyntable').dataTable({
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"fnServerParams": function (aoData) {
aoData.push({ "report_type": "Downline", "value": "Null" });
},
"sAjaxSource": "ajax/message_center_compose.asp",
"aoColumnDefs": [
{ "sWidth": "20px", "aTargets": [0] },
{ "sWidth": "60px", "aTargets": [1, 4, 5, 6] },
{ "bSortable": false, "aTargets": [0] },
{ "bSearchable": false, "aTargets": [0, 4] },
{ "sClass": "text-align-center", "aTargets": [0, 1, 5, 6] },
{ "sClass": "text-align-right", "aTargets": [4] }
],
"fnDrawCallback": function (oSettings) {
convertCheckbox();
doNotSendList(oTable, aDoNotSend);
verifyChecked(oTable, aDoNotSend, nTr);
},
"fnServerData": fnDataTablesPipeline,
"bDeferRender": true
});
[/code]
When checking firebug the report_type is never passed. It crashes when I visit the page. It worked before I added the fnServerParams.
And here is where it should be looking on the ajax page:
[code]
sql = sql & " EXEC [dbo].[MSGGetList]"
sql = sql & " @List = N'" & request("report_type") & "',"
[/code]
The request("report_type") is blank.
[code]
aoData.push({ "name": "report_type", "value": "Downline" })
[/code]