Author Topic: Extra parameter sent along when filtering  (Read 4735 times)

daan

  • Newbie
  • *
  • Posts: 6
    • View Profile
Extra parameter sent along when filtering
« on: September 26, 2014, 02:37:29 pm »
I'm evaluating the pro grid for the company I work for and we have a big requirement that I haven't been able to solve yet.
On most of our pages where we have the grids we also have the functionality to build more complex search filters. This is not part of the grid and is handles completely seperated. However, we want to be able to send along an id (stored in a hidden field) whenever you do a filtering in the grid.

Our code is done in MVC and the filtering is done via JSON remotely.
I've managed to get the grid to call this function:

Code: [Select]
public ActionResult GetValues(int pq_curPage, int pq_rPP, string pq_sort, string pq_filter) 

It returns the result correctly.

This is my testgrid so far:

Code: [Select]
$(function () {
        function pqDatePicker(ui) {
            var $this = $(this);
            $this
                .css({ zIndex: 3, position: "relative" })
                .datepicker({
                    yearRange: "-20:+0", //20 years prior to present.
                    changeYear: true,
                    changeMonth: true,
                    showButtonPanel: true,
                    onClose: function (evt, ui) {
                        $(this).focus();
                    }
                });
            //default From date
            $this.filter(".pq-from").datepicker("option", "defaultDate", new Date("01/01/1996"));
            //default To date
            $this.filter(".pq-to").datepicker("option", "defaultDate", new Date("12/31/1998"));
        }

        var dataModel = {
            location: "remote",
            sorting: "remote",
            dataType: "JSON",
            method: "GET",
            url: "Home/GetValues",
            getData: function (dataJSON) {
                var data = dataJSON.data;
                return { curPage: dataJSON.curPage, totalRecords: dataJSON.totalRecords, data: data };
            }
        }

        var obj = {
            flexWidth: true,
            editable: false,
            title: "ParamQuery Test Grid",
            pageModel: { type: "remote", rPP: 10, strRpp: "{0}" },
            filterModel: { on: true, mode: "AND", header: true },
            dataModel: dataModel
        };
        obj.colModel = [
            {
                title: "First Name", width: 400, dataIndx: "FirstName",
                filter: { type: 'textbox', condition: 'begin', listeners: ['change'] }
            },
               {
                   title: "Last Name", width: 400, dataIndx: "LastName",
                   filter: { type: 'textbox', condition: 'begin', listeners: ['change'] }
               },
               {
                   title: "Age", width: 50, dataIndx: "Age",
                   filter: { type: 'textbox', condition: 'begin', listeners: ['change'] }
               },
               {
                   title: "Start Date", width: 100, dataIndx: "StartDate",
                   filter: { type: 'textbox', condition: "between", init: pqDatePicker, listeners: ['change'] }
               },
               {
                   title: "Male", width: 100, dataIndx: "IsMale", dataType: "bool", align: "center",
                   filter: { type: "checkbox", subtype: 'triple', condition: "equal", listeners: ['click'] }
               },
               {
                   title: "Department", width: 100, dataIndx: "Department",
                   filter: {
                       type: "select",
                       condition: 'equal',
                       prepend: { '': '--Select--' },
                       valueIndx: "DepartmentId",
                       labelIndx: "Department",
                       listeners: ['change']
                   }
               }
        ];
        $("#testGrid").pqGrid(obj);

    });

So, how would I send along an extra parameter when filtering?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Extra parameter sent along when filtering
« Reply #1 on: September 26, 2014, 04:02:35 pm »
There are 2 options which would help you to send extra parameters / data while filter call to the remote server.

http://paramquery.com/pro/api#option-dataModel-postData

http://paramquery.com/pro/api#option-dataModel-postDataOnce

daan

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Extra parameter sent along when filtering
« Reply #2 on: September 26, 2014, 04:50:02 pm »
Thanks for a very quick answer!

I updated my dataModel like this:

Code: [Select]
var dataModel = {
            location: "remote",
            sorting: "remote",
            dataType: "JSON",
            method: "GET",
            url: "Home/GetValues",
            getData: function (dataJSON) {
                var data = dataJSON.data;
                return { curPage: dataJSON.curPage, totalRecords: dataJSON.totalRecords, data: data };
            },
            postData: { advancedQueryId: 0 }
        }

The action in the controller got an extra parameter:
Code: [Select]
public ActionResult GetValues(int pq_curPage, int pq_rPP, string pq_sort, string pq_filter, int advancedQueryId)
Then I used a dropdown to change the value and search.

Code: [Select]
$(document).on('change', '#AdvancedQuerySelector', function (e) {
            e.preventDefault();

            var x = $(this).val();
            $("#testGrid").pqGrid("option", "dataModel.postData", function (ui) {
                return { advancedQueryId: x };
            });

            $("#testGrid").pqGrid("refreshDataAndView");       
        });


That worked very well! Now I nearly done all the quick checks if it's possible for us to use this and it looks very good :)