Help needed extending server side processing with request variables.

Help needed extending server side processing with request variables.

jamesjw007jamesjw007 Posts: 35Questions: 0Answers: 0
edited July 2012 in General
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.

Replies

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    > How can I attach the items the user selects

    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
  • jamesjw007jamesjw007 Posts: 35Questions: 0Answers: 0
    I've looked over that and I can understand how that works. My new concern is how do I clear out the current data and bring in the new data with server side processing.

    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. =(
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    Here is an example of the way I do it:

    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.
  • jamesjw007jamesjw007 Posts: 35Questions: 0Answers: 0
    Hrm, I tried to get this started but it doesn't seem to be passing my params at all.

    [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.
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    It expects a name & value combination, if you want the name to be report_type and the value Downline it should be like this:

    [code]
    aoData.push({ "name": "report_type", "value": "Downline" })
    [/code]
  • jamesjw007jamesjw007 Posts: 35Questions: 0Answers: 0
    Oh I'm not used to that method. I made the changes and it is working again. Will keep playing with the see if I can get this working with all of the filters. :)
  • jamesjw007jamesjw007 Posts: 35Questions: 0Answers: 0
    Worked like a charm, thank you both! :)
This discussion has been closed.