Ticket T268885
Visible to All Users

ASPxGridView - How to use date constants in filter

created 10 years ago

[DevExpress Support Team: CLONED FROM T166826: ASPxFilterControl - Support predefined operations for date columns like in WinForms]
This functionality is sorely needed. Many of our users are asking for this. We allow our user to save grid layout. They can later pick it from a list and restore the layout as they had it. However, the need to be able to filter date fields based on relative dates. They need to be able to say [SomeDateField] >= TODAY. And, be able to save that as grid's layout for later retrieval. Please provide a work-around on how this can be done. Also, besides being able to use relative dates, they need to retain the ability to filter using absolute values.
If the grid control would allow to compare fields, such as [Field1] [Comparison] [Field2], then I could add a field called [Today] into the grid and let users compare to that field. But, this option is also missing. Please provide a usable work-around.

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

While there are no such built-in options available, the closest way to mimic this behavior is to use the approach from the ASPxGridView - Date auto filter example.

UPDATED:

Having prepared a sample, I have found another solution based on the specialized FunctionOperator functions (instead of combining the FilterDateType functions that are mainly intended for desktop GridControl/FilterControl controls):

C#
new BinaryOperator( new OperandProperty(e.Column.FieldName), //Left Operand new FunctionOperator() { OperatorType = FunctionOperatorType.Today }, //Right Operand BinaryOperatorType.GreaterOrEqual //Operator )

Please refer to the attached project.

    Show previous comments (7)

      Hello Eugene,

      Having prepared a sample, I have found another solution based on the specialized FunctionOperator functions (instead of combining the FilterDateType functions that are mainly intended for desktop GridControl/FilterControl controls):

      C#
      new BinaryOperator( new OperandProperty(e.Column.FieldName), //Left Operand new FunctionOperator() { OperatorType = FunctionOperatorType.Today }, //Right Operand BinaryOperatorType.GreaterOrEqual //Operator )

      Please refer to the attached project.

      EP EP
      Eugene Paradizov 10 years ago

        Mike,
        This works. I also implemented other variants, such as IsToday:
                   new GroupOperator(GroupOperatorType.And,    //Group Operator
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.Today), //Right Operand
                           BinaryOperatorType.GreaterOrEqual //Operator
                       ),
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.AddDays, new FunctionOperator(FunctionOperatorType.Today), 1), //Right Operand
                           BinaryOperatorType.Less //Operator
                       )
                   )
        IsYesterday:
                   new GroupOperator(GroupOperatorType.And,    //Group Operator
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.AddDays, new FunctionOperator(FunctionOperatorType.Today), -1), //Right Operand
                           BinaryOperatorType.GreaterOrEqual //Operator
                       ),
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.Today), //Right Operand
                           BinaryOperatorType.Less //Operator
                       )
                   )
        IsTomorrow:
                   new GroupOperator(GroupOperatorType.And,    //Group Operator
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.AddDays, new FunctionOperator(FunctionOperatorType.Today), 1), //Right Operand
                           BinaryOperatorType.GreaterOrEqual //Operator
                       ),
                       new BinaryOperator(
                           new OperandProperty(e.Column.FieldName), //Left Operand
                           new FunctionOperator(FunctionOperatorType.AddDays, new FunctionOperator(FunctionOperatorType.Today), 2), //Right Operand
                           BinaryOperatorType.Less //Operator
                       )
                   )
        All these are working well. The only issue now is how the can edit the overall filter (for non-date columns) and the newly added custom functions? If I enable Filter Row and Filter Builder (it's a must for all other columns and complex logic), then these custom functions get erased right after I edit the filter in the Filter Builder. Of course, they are not shown in the Builder, so they get erased. So, how do we make it all work nicely together?
        Our grids have tens of columns of all kinds of data types. So, I must have the Filter Row and Filter Builder enabled. How could I merge them with custom functions and still have some workable solution?

          Hello Eugene,

          Thank you for informing me of your progress.

          >>How could I merge them with custom functions and still have some workable solution?

          As I mentioned earlier, currently, there is no way to use these filters simultaneously. The FilterBuilder (ASPxFilterControl) does not yet support rendering such a layout, and the AutoFilterRow displays an editor with a single value set according to the AutoFilterCondition.
          We are working on improving the "date range/intervals" filtering functionality and on providing some new features in the in the next major version (15.2).

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.