This is a migrated thread and some comments may be shown as answers.
FilterExpression fails for datetime column
4 Answers 46 Views
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 2
Hans asked on 29 Mar 2010, 04:09 PM
void RadGrid1_ItemCommand2(object source, GridCommandEventArgs e)  
        {  
            if (e.CommandName == RadGrid.FilterCommandName && ((Pair)e.CommandArgument).Second.ToString() == "orderdatetime")  
            {  
                e.Canceled = true;  
                GridFilteringItem filterItem = (GridFilteringItem)e.Item;  
                string filterPattern = "3/1/2010";  
                string filterPatternAssist = "4/1/2010";  
                filterPattern = "" + filterPattern + " <= [orderdatetime] AND [orderdatetime] <= " + filterPatternAssist + "";  
                GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("orderdatetime");  
                dateColumn.CurrentFilterFunction = GridKnownFunction.Between;  
                RadGrid1.MasterTableView.FilterExpression = filterPattern; // Expression expected  
                RadGrid1.Rebind();  
            }  
        } 

Filtering a datetime column using a dropdown triggers the above function. The Rebind shows the error "Expression expected". How do I fix this ? This code is the same as all the examples I've found so far. The only difference is that I'm using a LINQ datasource.

Please advise.

4 Answers, 1 is accepted

Sort by
0
Foenix
Top achievements
Rank 1
answered on 29 Mar 2010, 09:48 PM
void RadGrid1_ItemCommand2(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.FilterCommandName && ((Pair)e.CommandArgument).Second.ToString() == "orderdatetime"
    { 
        //  Why? Do you really need to cancel standard event treatment? 
        // e.Canceled = true; 
        GridFilteringItem filterItem = (GridFilteringItem)e.Item; 
        string filterPattern = "3/1/2010"
        string filterPatternAssist = "4/1/2010"
        //filterPattern = "" + filterPattern + " <= [orderdatetime] AND [orderdatetime] <= " + filterPatternAssist + ""; 
        GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("orderdatetime"); 
         
        Pair args = (Pair)e.CommandArgument; 
         
        dateColumn.CurrentFilterFunction = filterPattern + " " + filterPatternAssist; 
        dateColumn.CurrentFilterFunction = GridKnownFunction.Between; 
        args.First = "11";   // 11 means "Between" 
         
        //RadGrid1.MasterTableView.FilterExpression = filterPattern; // Expression expected 
        //RadGrid1.Rebind();   
    } 
 

Try it.
0
Hans
Top achievements
Rank 2
answered on 30 Mar 2010, 07:54 AM

Code has no effect.

This line:

dateColumn.CurrentFilterFunction = filterPattern + " " + filterPatternAssist;

cannot be correct, because CurrentFilterFunction is an enum, specified by the line below it.

Is there any documentation on the args ? How did you come up with this ?

0
Hans
Top achievements
Rank 2
answered on 30 Mar 2010, 09:46 AM
<telerik:RadComboBox ID="comboPeriod" runat="server" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("orderdatetime").CurrentFilterValue %>' OnClientSelectedIndexChanged="SelectedPeriodIndexChanged">
                                                <Items>
                                                    <telerik:RadComboBoxItem Text="" Value="-1" />
                                                    <telerik:RadComboBoxItem Text="Vandaag" Value="29-03-2010" />
                                                    <telerik:RadComboBoxItem Text="Laatste 7 dagen" Value="22-03-2010" />
                                                    <telerik:RadComboBoxItem Text="Laatste maand" Value="01-03-2010" />
                                                </Items>
                                            </telerik:RadComboBox>
                                            <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
                                                <script type="text/javascript">
                                                    function SelectedPeriodIndexChanged(sender, args) {
                                                        var selectedindex = args.get_item().get_value();
                                                        /*
                                                        var filter = "";
                                                        switch (selectedindex) {
                                                            case 0:
                                                                filter = "29-03-2010";
                                                                break;
                                                            case 1:
                                                                filter = "22-03-2010";
                                                                break;
                                                            case 2:
                                                                filter = "01-03-2010";
                                                                break;
                                                        }
                                                        */
                                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                        if (selectedindex != "-1") {
                                                            tableView.filter("orderdatetime", selectedindex, "GreaterThanOrEqualTo");
                                                        }
                                                        else {
                                                            tableView.filter("orderdatetime", "", "NoFilter");
                                                        }
                                                    }
                                                </script>
                                            </telerik:RadScriptBlock> 

The above code does what I want. However, if I change the values of the combo to -1, 0, 1 and 2 and use the commented code and use filter instead of selectedindex in the tableView.filter() then I get errors or nothing at all.

For this moment, my solution is to connect to a custom coded datasource, that will return the combobox items.

0
Foenix
Top achievements
Rank 1
answered on 30 Mar 2010, 01:48 PM
Sorry, my fault. It's just a "copy-paste" error. The correct expression is dateColumn.CurrentFilterValue = filterPattern + " " + filterPatternAssist;
Tags
Grid
Asked by
Hans
Top achievements
Rank 2
Answers by
Foenix
Top achievements
Rank 1
Hans
Top achievements
Rank 2
Share this question
or