1. #1
    Ext User
    Join Date
    Apr 2010
    Posts
    4
    Vote Rating
    0
    sizemorew is on a distinguished road

      0  

    Default Unable to Retrieve Only Null Dates with Ext.ux.grid.GridFilters

    Unable to Retrieve Only Null Dates with Ext.ux.grid.GridFilters


    I'm working with a grid where I need a button to filter items that have been closed. These are flagged by the Closed Date which--if an item is still open--should be set to null.

    I'm using the following code to try and set the filter but I found a rather bizarre bug where instead of filtering out the items that have a Closed Date, it's filtering to show only the items with a Closed Date.

    Code:
    filters.getFilter('closedDate').setValue({on: null});
    filters.getFilter('closedDate').setActive(true);
    grid.getStore().reload();
    I've tried setting the value simply to null, but that does absolutely nothing but sit there. I also tried using a different filter to check for a null in the Closed By field we have in place but that also does nothing.

    So my question is this: Is there a way to filter using GridFilters where I retrieve only those records with null dates?

    I've already poked my nose through the User Extension Documentation and have been looking through the main Ext.ux.grid.GridFilters thread. I've also been hunting through the forums for the past two hours and will continue looking. Any and all assistance is much appreciated.

    Additional Information: I also tried filtering after and before certain dates to see if the records with null dates would show up in the list. They didn't.
    Last edited by sizemorew; 12 Jan 2011 at 9:43 AM. Reason: Added additional details of work done.

  2. #2
    Ext User
    Join Date
    Apr 2010
    Posts
    4
    Vote Rating
    0
    sizemorew is on a distinguished road

      0  

    Default SOLVED

    SOLVED


    Resolved the issue where I was unable to filter by empty dates. Posting code here in case someone else wants to do the same thing.

    In DateFilter.js

    Add to private variables:
    Code:
    /**
     * @cfg {String} blankText
     * Defaults to 'Blank'
    */
        blankText: 'Blank',
    Add to the init function:
    Code:
    var blankCheckbox = new Ext.menu.CheckItem({
         text: this['blankText'],
         listeners: {
              scope: this,
              checkchange: this.onCheckChange
         },
              itemId: 'blank'
    });
            
    this.fields['blank'] = blankCheckbox;
    this.menu.add(blankCheckbox);
    Replace onMenuSelect:
    Code:
    var fields = this.fields,
         field = this.fields[menuItem.itemId];
            
    field.setChecked(true);
            
    if (field == fields.blank){
         fields.before.setChecked(false, true);
         fields.after.setChecked(false, true);
         fields.on.setChecked(false,true);
    }
    else if (field == fields.on) {
         fields.before.setChecked(false, true);
         fields.after.setChecked(false, true);
         fields.blank.setChecked(false, true);
    } else {
         fields.blank.setChecked(false,true);
         fields.on.setChecked(false, true);
         if (field == fields.after && fields.before.menu.picker.value < value) {
              fields.before.setChecked(false, true);
         } else if (field == fields.before && fields.after.menu.picker.value > value) {
              fields.after.setChecked(false, true);
         }
    }
    this.fireEvent('update', this);
    Replace getValue:
    Code:
    var key, result = {};
    for (key in this.fields) {
         if (key == 'blank')
         {
              result[key] = this.fields[key].checked;
         }
         else if (this.fields[key].checked) {
              result[key] = this.fields[key].menu.picker.getValue();
         }
    }
    return result;
    Replace setValue:
    Code:
    var key;
    for (key in this.fields) {
         if (key == 'blank')
         {
              this.fields[key].setChecked(value[key]);
         }
         else if(value[key]){
              this.fields[key].menu.picker.setValue(value[key]);
              this.fields[key].setChecked(true);
         } else if (!preserve) {
              this.fields[key].setChecked(false);
         }
    }
    this.fireEvent('update', this);
    Add to validateRecord before the check if val is a date:
    Code:
    if (this.fields['blank'].checked)
    {
         return (val == null);
    }
    Last edited by sizemorew; 13 Jan 2011 at 10:28 AM. Reason: Added config option to change the Blank checkbox's text value.

  3. #3
    Ext User
    Join Date
    Apr 2010
    Posts
    4
    Vote Rating
    0
    sizemorew is on a distinguished road

      0  

    Default UPDATE

    UPDATE


    Fixed a few bugs that could cause the GridFilters object to crash.

    In getSerialArgs, replace with this code:
    Code:
    var args = [];
    for (var key in this.fields) {
         if (key == 'blank')
         {
              if (this.fields[key].checked)
              {
                   args.push({
                        type: 'boolean',
                        value: this.fields[key].checked
                   });
              }
         }
         else
         {
              if(this.fields[key].checked){
                   args.push({
                        type: 'date',
                        comparison: this.compareMap[key],
                        value: this.getFieldValue(key).format(this.dateFormat)
                   });
              }
         }
    }
    return args;
    In getFieldValue, replace with this code:
    Code:
    if (item == 'blank')
    {
         return this.fields[item].checked;
    }
    else
    {
         return this.fields[item].menu.picker.getValue();
    }
    In getPicker, wrap an if statement around the return statement like this:
    Code:
    if (item != 'blank')
    {
         return this.fields[item].menu.picker;
    }
    Sorry for any bugs that people had cropping up when using my modification. The little gremlin didn't show up until recently on my end.

  4. #4
    Sencha User darthwes's Avatar
    Join Date
    Mar 2010
    Posts
    633
    Vote Rating
    -13
    darthwes can only hope to improve

      0  

    Default


    1.) You can use a static constant (such as the string "null" or perhaps a string like "-" or "undef" or something) so that when the user puts that into the filter you can catch it on your backend and modify your filtering clause.

    2.) You can use a list filter and use "Open" and/or "Closed" as list options, catch it on the backend and modify the filtering clause.

    I don't think modifying the grid filters ux is a good idea because of maintenance costs (like what happens when you move to the next version of ext/grid filters, how does the next programmer know how this works? Etc. Just my .02....
    Wes

Similar Threads

  1. Unable to extend Ext.data.JsonStore (proxy null)
    By alois.cochard in forum Ext: Q&A
    Replies: 2
    Last Post: 4 Nov 2010, 2:38 AM
  2. unable to retrieve data in textbox rendered by ext datepicker
    By anilkamath in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 24 Jan 2010, 10:14 PM
  3. Unable to retrieve data from store
    By nikhilkrishnan in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Jun 2009, 12:03 AM
  4. unable to retrieve data from XML FEED
    By info in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 27 Feb 2009, 8:30 AM

Thread Participants: 1