Author Topic: Filter not working  (Read 4762 times)

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Filter not working
« on: February 12, 2014, 12:10:41 am »
Hi,

I'm replicating the "Header remote filtering" from your demos page.

I create the filter function, then I set the filter option in column "categoria" to whatever value the user types in the box.
I have filterModel on with headers.

It all looks ok but it doesn't filter.

You can see it here:
http://www.portal-gestao.com/youbudgetz.html

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Filter not working
« Reply #1 on: February 12, 2014, 10:01:28 am »
In your case dataModel.location = "remote", so you need to implement remote filtering.

http://paramquery.com/pro/demos/filter_header


If you need local filtering either use dataModel.location = 'local' or make dataModel.location to 'local' just before call to filter function and revert dataModel.location to 'remote' after filter call. Please keep in mind that all the data should be on client side for local filtering.

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Filter not working
« Reply #2 on: February 13, 2014, 05:20:51 pm »
I want the table to display the data for a specific month/year.

I have a variable in the client side that contains the month (eg:3) and the year (eg:2014).

How do I pass this data to PHP and include it in the query?

I read the docs and tried in JS:

Code: [Select]
dataModel: {
            //paging: "local",
            dataType: "JSON",
            recIndx: "id",
            location: "remote",
            postData: {monthSelect:3, yearSelect:2014},
            url: "myscript.php",
            getData: function (response) {
                return { data: response.data };
            }
        },

And in PHP:
Code: [Select]
else if( isset($_POST['what????'])){
$month=???;
        $year=????;
}

If there's a better alternative to this, like downloading the whole data and the filtering locally, great. But I also need the totals for columns to reflect only the loaded month/year.

Thanks for helping!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Filter not working
« Reply #3 on: February 13, 2014, 05:56:43 pm »
1) You have to call refreshDataAndView after setting postData to make an immediate server request.

Your method should be POST if you want to capture it as $_POST["monthSelect"] and $_POST["yearSelect"]

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


=============================================================
2) Alternative method:

call to filter method would automatically make a server request
Code: [Select]
  $grid.pqGrid("filter", ({
     data: [
            { dataIndx: dataIndx1, condition: condition1, value: value1 }, 
            { dataIndx: dataIndx2, condition: condition2, value: value2 }
      ]
  });


and on server side:

Code: [Select]
$_POST["pq_filter"] =
{
    mode => mode, //('AND' / 'OR' ) 
    data => [
        { dataIndx=> dataIndx1, condition=> condition1, value=> value1 }, 
        { dataIndx=> dataIndx2, condition=> condition2, value=> value2 }
     ]
}

These 2 demos are based on alternative method.
http://paramquery.com/pro/demos/filter_header
http://paramquery.com/pro/demos/filter
« Last Edit: February 13, 2014, 09:17:58 pm by paramquery »

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Filter not working
« Reply #4 on: February 13, 2014, 10:19:24 pm »
Hey,

Thanks for your support!

What worked for me:
1-build an event listener with a widget to load current monht and select +/- another month.
2-pass the variables of month and year selecte to dataModel
3-redefine obj.dataModel when month changes
4-use refreshDataAndView to reload the table with the selected month.

Not straightforward but this is exactly what I wanted.
 :D