Author Topic: Initial range filter values based on min and max column/dataIndx value  (Read 2416 times)

interloper10

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
I can set the initial date range filter using value & value2.

Is it possible to set the initial date range filter values based on the min and max value of the associated dataIndx/column values?  I don't necessarily need to apply the filter because it is inclusive of all results (already), but I just want to make it convenient for user to see the range of values and to initialize the pqdatePicker.

I've tried to initialize with getData like I would a pqSelect, but not sure how to get a min/max value on that subset.

With this in mind, this may be consideration for adding helper methods like getColMinValue/getColMaxValue(dataIndx).

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: Initial range filter values based on min and max column/dataIndx value
« Reply #1 on: December 16, 2016, 07:21:28 pm »
That's a good question. It boils down to getting max and min values from a column for which aggregates can be used.

http://paramquery.com/pro/api#method-aggregate

Code: [Select]
//get minimum and maximum dates in Order Date column.
var arr = grid.option('dataModel.data').map(function(rd){
return rd.OrderDate;
}),
column = grid.getColumn({dataIndx: 'OrderDate'}),               
minDate = pq.aggregate.min(arr, column),
maxData = pq.aggregate.max(arr, column);

I've updated this example: http://paramquery.com/pro/demos/filter_header_local

interloper10

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Initial range filter values based on min and max column/dataIndx value
« Reply #2 on: December 16, 2016, 09:54:38 pm »
Awesome thank you.  Wanted to make you aware that you have minDatE and maxDatA in the code - just something to be aware of with your variable names.

Also, I ended up implementing this after the grid gets defined so that I could show the initial values.

Code: [Select]
               
                var column = grid.getColumn({dataIndx: 2});
                var filter = column.filter;
               
                //get minimum and maximum dates in Order Date column.
                var arr = grid.option('dataModel.data').map(function(rd){
                    return rd[2];
                });
             
                var minDate = pq.aggregate.min(arr, column),
                    maxDate = pq.aggregate.max(arr, column);
                //set default From date
                filter.value = minDate;
                filter.value2 = maxDate;

Thank you sir! :)