Pass a search filter via URL parameter

Pass a search filter via URL parameter

scsc_techscsc_tech Posts: 7Questions: 0Answers: 0
edited January 2012 in General
I already have a datatable up and running which shows open support tickets. On the header of all the pages I have a count of overdue tickets. I want that count to be a link, so when they click on it, it takes them to the datatables page and filters for overdue. My thought was making the link datatable.cfm/?sSearch_6=overdue

I am struggling to figure out how to pull the URL parameter and perform the search on the table. I also need it to operate normally if no parameter exists.

Thanks!

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    So basically you want to apply a filter to the table during its initialisation? That is possible using the aoSearchCols initialisation parameter. You will need to get the search string (window.location or something like that) and then apply it - but aoSearchCols is the way to define an initial column filter.

    Allan
  • scsc_techscsc_tech Posts: 7Questions: 0Answers: 0
    Unfortunately no luck with aoSearchCols even when hard coding

    [code]

    $(document).ready(function() {
    var oTable = $('#example').dataTable({
    "iDisplayLength":25,
    "bAutoWidth":false,
    "bJQueryUI": true, /* Enables ThemeRoller */
    "sPaginationType": "full_numbers", /* Pagination Display */
    "bProcessing": true, /* Show processing overlay */
    "bServerSide": true, /* Use serverside processing */
    "sAjaxSource": "/prism/includes/grids/tickets_handler.cfm", /* Serverside logic */
    "aaSorting": [[8, "desc"],[ 3, "asc" ],[ 9, "asc" ]], /* Primary sorting (column 1 ascending) */
    "bStateSave": true, /* Save the view state*/
    "aoColumns": [
    /*0 ID */ { "bSearchable": false, "bVisible": false }, /* Disables the visibility of the ID field */
    /*1 Sub Dept */ { "bSearchable": true, "bVisible": false }, /* Disables the visibility of the ID field */
    /*2 Age */ null,
    /*3 Priority */ null,
    /*4 System */ null,
    /*5 Subject # */ null,
    /*6 Status */ null,
    /*7 Due # */ null,
    /*8 ticket_assigned_status*/ { "bSearchable": false, "bVisible": false },/* Disables the visibility of the ID field */
    /*9 create_timestamp */ { "bSearchable": false, "bVisible": false }, /* Disables the visibility of the ID field */
    /*10 datatables_cell_color_code */ { "bSearchable": false, "bVisible": false } /* SQL handles logic of what the color code should be...makes Javascript logic simple */

    ],
    "aoSearchCols": [
    /*0 ID */ null,
    /*1 Sub Dept */ null,
    /*2 Age */ null,
    /*3 Priority */ null,
    /*4 System */ null,
    /*5 Subject # */ null,
    /*6 Status */ { "sSearch": "Assigned" },
    /*7 Due # */ null,
    /*8 ticket_assigned_status*/ null,
    /*9 create_timestamp */ null,
    /*10 datatables_cell_color_code */ null
    ],
    //"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    // /* Replace 1 or 0 with Yes or No */
    // if ( aData[4] == "1" )
    // {
    // $('td:eq(3)', nRow).html('Yes' );
    // }
    // else if ( aData[4] == "0" )
    // {
    // $('td:eq(3)', nRow).html('No');
    // }
    // return nRow;
    //},
    // CHANGE ROW TO GREEN IF STATUS IS SUBMITTED
    "fnRowCallback": function( nRow, aaData, iDisplayIndex, iDisplayIndexFull ) {
    if ( aaData[6] == "Submitted" )
    {
    // greencell IS THE CSS CLASS WITH THE CORRECT background-color
    nRow.className = "greencell" + nRow.className
    }
    //return nRow;

    else if (aaData[10] == "1")
    {
    //due date is overdue...color cell red
    //nRow.className = "redcell" + nRow.className
    var cellorder = "redcell" + nRow.className
    $('td:eq(5)', nRow).toggleClass(cellorder);
    }

    return nRow;

    },
    fnDrawCallback: function() {
    $('td').bind('mouseenter', function () { $(this).parent().children().each(function(){$(this).addClass('datatablerowhighlight');}); });
    $('td').bind('mouseleave', function () { $(this).parent().children().each(function(){$(this).removeClass('datatablerowhighlight');}); });

    clickRowHandler();
    }
    }); /* End datatable*/
    [/code]
  • scsc_techscsc_tech Posts: 7Questions: 0Answers: 0
    any thoughts?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    As you can see in this example the initialisation should be applying the filtering: http://live.datatables.net/akibef/edit . So I guess the question is, does your cfm server-side processing script provide column filtering options?

    Allan
  • shanershaner Posts: 1Questions: 0Answers: 0
    I hope this thread is still active. I did follow the instructions and it does work for me. The only issue I have now is spaces. So if I have a word that is "IAS 19" the space is ignore and I get no results. How do I convert the space?

    Also is there a way to have it so that the word would show in the Search field?
This discussion has been closed.