Author Topic: Filter on date column using checkbox for past due  (Read 3382 times)

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Filter on date column using checkbox for past due
« on: May 18, 2020, 02:46:48 am »
Hi

When building the colModel the below will show records where the due date is less than today, however it still shows blank values.
I tried notempty but could not get it to work.
Also how can I put this in a checkbox in the toolbar.

{title: "Due Date", width: 30, dataType: "date", filter: {
crules: [
{ condition: "less", value: new Date()}, //set initial value of filter
{ condition: "great", value: ""}
]
}},

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #1 on: May 18, 2020, 09:13:39 am »
Please use notempty condition.

Code: [Select]
crules: [
 { condition: "less", value: new Date()}, //set initial value of filter
 { condition: "notempty"}],
 mode: "AND"
]

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #2 on: May 18, 2020, 07:40:08 pm »
Thanks paramvir,
That works great when loading, however how can that filter be turned on and off based on a checkbox in the toolbar?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #3 on: May 19, 2020, 09:02:11 am »
For runtime manipulation of filter from checkbox in toolbar, please call filter method in checkbox listener.

https://paramquery.com/pro/api#method-filter

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #4 on: May 19, 2020, 11:33:24 am »
Hi Paramvir,
Struggling with this.
Tried a number of combinations. 
How do I get the column object?
How do I know if the checkbox is checked or not?
How do I clear this filter when it is unchecked?



                        {
                            type: 'checkbox',
                            label: "Over Due",
                            listener: function () {
                                this.colModel.filter({
                                    oper: 'replace',
                                    rules: [
                                        {
                                            dataIndx: 'Due Date',
                                            mode: "AND",
                                            crules: [
                                                {condition: "less", value: new Date()}, //set initial value of filter
                                                {condition: "notempty"}]
                                        }]
                                })
                            }
                        },


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #5 on: May 19, 2020, 07:07:41 pm »
https://paramquery.com/pro/api#method-filter

There is no need of column object in filter method call. dataIndx is used in filter method call.

evt.target.checked provides the checkbox state. Example: https://paramquery.com/pro/demos/wrap

Filter is cleared by passing empty crules array []

Please share a jsfiddle if still facing problems.

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #6 on: May 20, 2020, 04:21:19 am »
Thanks paramvir, 
The filter and checkbox work perfectly now if the columns don't move.  When columns move it no longer works.
Here is the jsfiddle: https://jsfiddle.net/WebSalesDesign/hcw512dk/6/

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #7 on: May 20, 2020, 09:57:23 am »
your findTitle function logic is incorrect, it returns colIndx instead of dataIndx.

Corrected version:

Code: [Select]
function findTitle(CM, val) {
    return (CM.find(function(col){
    return col.title == val
    }) || {}).dataIndx;
};

https://jsfiddle.net/4j0bgmua/

Note: It's easier to use json data instead of array data, in that case you don't need findTitle function.

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Filter on date column using checkbox for past due
« Reply #8 on: May 21, 2020, 09:17:37 am »
Thanks once again Paramvir,
This works.
I originally used array to reduce data size and increase speed, however I will switch it over to json data like you suggested.