aoData and sSearch_X values

aoData and sSearch_X values

MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
edited September 2011 in General
I need to set the initial sSearch values. when I do this:
[code]
aoData.push({"name":"sSearch_9", "value":"{segment_2}"}
, {"name":"sSearch_18", "value":"{segment_3}"}
, {"name":"sSearch_19", "value":"{segment_4}"}
, {"name":"sSearch_20", "value":"{segment_5}"});
[/code]

It actually places another parameter on the stack with the same name.
How would I change the original value?

The {segment_X} values are from ExpressionEngine. We are using the URL path, which is what the segment_X values are for, to set the filtering like this:

http://ourURL.com/page/segment_2/segment_3/segment_4/segment_5

This allows our users to use the back button to go to previous searches (filters) and also to send the URL to others with the filter intact.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited September 2011
    [code]
    for (i in aoData) {
    switch(aoData[i].name) {
    case "sSearch_9": aoData[i].value="{segment_2}"; break;
    case "sSearch_18": aoData[i].value="{segment_3}"; break;
    case "sSearch_19": aoData[i].value="{segment_4}"; break;
    case "sSearch_20": aoData[i].value="{segment_5}"; break;
    }
    }
    [/code]
  • MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
    If I do it like that and try to dynamically filter the table using fnFilter, the sSearch_X value does not get set in the post.

    Definition:
    [code]
    oTable = $('#scheduleTable').dataTable( {
    "oLanguage": {
    "sInfoFiltered": ""
    },
    "sPaginationType": "full_numbers",
    "bProcessing": true,
    "bJQueryUI": true,
    "bServerSide": true,
    "aaSorting": [],
    "sAjaxSource": "/files/schedule_filter.php",
    "aoColumns": [null /* Location */
    , { "iDataSort": 17 } /* FormalDate */
    , null /* Program_Title */
    , null /* Price */
    , null /* Information */
    , { "bVisible": false } /* ProgramCode */
    , { "bVisible": false } /* ProgramGroup */
    , { "bVisible": false } /* EventCode */
    , { "bVisible": false } /* LocCity */
    , { "bVisible": false } /* LocState */
    , { "bVisible": false } /* LocAddress */
    , { "bVisible": false } /* LocName */
    , { "bVisible": false } /* LicenseeURL */
    , { "bVisible": false } /* GateKeeper_length */
    , { "bVisible": false } /* SeatsAreAvailable */
    , { "bVisible": false } /* LocLatitude */
    , { "bVisible": false } /* LocLongitude */
    , { "bVisible": false
    , "sType": "date" } /* StartDate */
    , { "bVisible": false } /* Months */
    , { "bVisible": false } /* Zip_Code */
    , { "bVisible": false } /* Programs */
    ],
    "sDom": '<"top">rt<"bottom"ilp><"clear">',
    "fnServerData": function( sSource, aoData, fnCallback ) {
    for (i in aoData) {
    switch(aoData[i].name) {
    case "sSearch_9": aoData[i].value="{segment_2}"; break;
    case "sSearch_18": aoData[i].value="{segment_3}"; break;
    case "sSearch_19": aoData[i].value="{segment_4}"; break;
    case "sSearch_20": aoData[i].value="{segment_5}"; break;
    }
    }
    aoData.push({"name":"debug", "value":"no"});
    $.ajax( {"dataType": 'json'
    , "type": "POST"
    , "url": sSource
    , "data": aoData
    , "success": fnCallback
    } );
    }
    } );
    [/code]

    Setting the filter dynamically like this:
    [code]
    $("#state").blur(function() {
    var src = $(this).val();
    oTable.fnFilter(src, 9);
    });
    $("#months").blur(function() {
    var src = $(this).val();
    oTable.fnFilter(src, 18);
    });
    $("#programs").blur(function() {
    var src = $(this).val();
    oTable.fnFilter(src, 19);
    });
    $("#zip").blur(function() {
    var src = $(this).val();
    oTable.fnFilter(src, 20);
    });
    [/code]

    But sSearch_9 is never set when typing in a value and exiting the #state input.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited September 2011
    If this is the same code on your demo link, seems to be working for me (I've filtered several states successfully)

    and looking in the debugger, value was set for sSearch_9

    chrome 12
  • MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
    Ok, I redid everything, got rid of the fnFilter calls because I'm just redirecting the user based on a dynamically constructed URL built from the filter criteria and it works great.
This discussion has been closed.