This is a migrated thread and some comments may be shown as answers.

Issue with filtering on multiple columns when MasterTableView.EnableColumnsViewstate=false

5 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mayank
Top achievements
Rank 1
Mayank asked on 28 Jan 2010, 10:49 PM
Hi,

We have Rad Grid with design time declaration and column structure load at page load. 

Also, we want columns to be configured during postbacks so we have set EnableColumnsViewState=false as per suggested in help article. (Keeping EnableColumnsViewState=true within postback is giving duplicate control ids errors)

By above settings, we are loosing feature of column filtering on multple columns.

Filtering with one column is working fine but once we filter on another column to further drill down the result, it looses the first filter value and returns results for the second filter value. Also, filter control(text box) on first column gets cleared.

This is working fine if are setting EnableColumnsViewState=true.

Please provide us fix or work-around to maintain and apply filters on multiple columns one by one.

Regards,
Vishal




5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 29 Jan 2010, 08:17 AM
Hi Mayank,

You do need the viewstate if you are to have multi-column filtering. As for the duplicate columns issue,have you wrapped your column creation code within a if (!IsPostBack){ } condition. Please, follow closely the instructions on programmatically creating the gird's structure given in the following help article (paragraph: Dynamically defining structure of a statically-declared grid):

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

I hope this helps.

Best wishes,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mayank
Top achievements
Rank 1
answered on 29 Jan 2010, 10:56 AM
Hi Tsvetoslav,

We are aware of the fact that grid structure should be rendered within (!Postback) but as I have already mentioned the scenario where user have capability to configure grid columns during page postbacks too. (thorough column list popup to be selected)

This applies the use of MaintainColumnsViewstate=false to create columns dynamically during postbacks too.

Is it possible(or some work-around) to maintain filterexpression even when we have MaintainColumnsViewstate=false?

Thanks,
Vishal


0
Tsvetoslav
Telerik team
answered on 03 Feb 2010, 04:58 PM
Hello Mayank,

As mentioned before, this scenario is not supported. As for a work-around for maintaining the filterexpression, you can certainly do so by keeping the CurrentFilterValue and CurrentFilterFunction in a ViewState or Session variable and construct the filter expression over and over again on each postback.

Regards,
Tsvetoslav
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Sudip
Top achievements
Rank 1
answered on 15 May 2014, 10:48 PM
It is not working on multiple column filter. Please help.

please see the logic below

void RadGridItemCommand(object source, GridCommandEventArgs e)
            if (commandName == RadGrid.FilterCommandName)
            {
e.Canceled = true;

                    string filterExpress = ClearFilterExpression(e.Item.OwnerTableView.FilterExpression, gridBoundColumn.UniqueName);
                    BuildFilterExpression(colName, value, gridBoundColumn.DataTypeName, ref filterExpress);
                    e.Item.OwnerTableView.FilterExpression = filterExpress;

                    e.Item.OwnerTableView.OwnerGrid.Rebind();
}
}

private static string ClearFilterExpression(string filterExpression, string columnName)
        {
            filterExpression = filterExpression.Replace("(", string.Empty);
            filterExpression = filterExpression.Replace(")", string.Empty);

            string[] filterExpressionParts = filterExpression.Split(new string[] { " AND " }, StringSplitOptions.None);
            ArrayList list = new ArrayList(filterExpressionParts);
            for (int i = list.Count - 1; i >= 0; i--)
            {
                if (list[i].ToString().StartsWith("[" + columnName +"]"))
                {
                    list.Remove(list[i]);
                }
            }

            filterExpressionParts = (string[])list.ToArray(typeof(string));

            return string.Join(" AND ", filterExpressionParts);
        }

private static void BuildFilterExpression(string field, string value, string dataTypeName, ref string filterExpression)
        {
            string filter = "";


            //http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html
            if (dataTypeName == "System.String")
            {
                //filter = "(iif(" + field + "==null,\"\", " +
                //                 field + ").ToString().Contains(\"" + value +
                //                 "\"))";
                
                filter = "([" + field + "] LIKE '%" + value + "%')";
            }
            else if (dataTypeName.Contains("System.Int"))
            {
                //if (!string.IsNullOrEmpty(field) && !string.IsNullOrEmpty(value))
                //    filter = "(" + field + "==" + value + ")";
                filter = "([" + field + "] = " + value + ")";
            }

            if (filterExpression == "")
            {
                filterExpression = filter;
            }
            else
            {
                filterExpression = "((" + filterExpression + ") AND " + filter + ")";
            }
        }
0
Angel Petrov
Telerik team
answered on 20 May 2014, 05:01 PM
Hi Sudip,

The provided code seems to use global variables which complicates the task of finding the root cause of the issue. Could you please share with us the entire page markup and code-behind so we could carefully examine the implementation? Once we have a better view over the exact setup we should be able to provide a more precise answer.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Mayank
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Mayank
Top achievements
Rank 1
Sudip
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or