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

[Solved] Issue storing/restoring sorting/filtering on an Grid using AjaxBinding

7 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stephen
Top achievements
Rank 1
Stephen asked on 18 Feb 2010, 05:28 PM
Hello,
We have implemented custom storing/restoring of the grid sorting/filtering so that these settings are persisted for the user when they navigate away and then back to the grid. This is all working as expected, except for one bug; when the ajaxRequest for the grid is fired the icons indicating the sorted state vanish (despite the data remaining sorted correctly) and subsequent sorting overwrites the existing sorting, instead of appending to it.

For clarification, the binding of the descriptors is done as follows:

// Grid definition code etc

if (!Model.GroupState.SortDescriptors.IsNullOrEmpty()) 
   foreach (var sortDescriptor in Model.GroupState.SortDescriptors) 
   { 
       if (!grid.DataProcessor.SortDescriptors.Contains(sortDescriptor)) 
       { 
           grid.DataProcessor.SortDescriptors.Add(sortDescriptor); 
       } 
   } 
if (!Model.GroupState.FilterDescriptors.IsNullOrEmpty()) 
   foreach (var filterDescriptor in Model.GroupState.FilterDescriptors.ConvertAll(f => (IFilterDescriptor)f)) 
   { 
       if (!grid.DataProcessor.FilterDescriptors.Contains(filterDescriptor)) 
       { 
           grid.DataProcessor.FilterDescriptors.Add(filterDescriptor); 
       } 
   } 
}

grid.Render();

I have noticed a workaround for this issue was posted by Kevin Watkins here, and was wondering if there were any plans to incorporate this fix (or your own way of fixing the issue) back into the source code? We would rather avoid customising our locally held source code with changes that are not going to be included in future releases of the product, but this appears to be a bug that needs resolving for our use case.

Alternatively, if there is something that we are doing wrong in our implementation please let me know.

Thanks
Stephen

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 07:48 AM
Hi Stephen,

We plan to allow initially sorting, filtering and paging the grid in the upcoming release.
Till then we can only offer you a workaround - to update with JavaScript the sort state of the icons.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Stephen
Top achievements
Rank 1
answered on 19 Feb 2010, 09:45 AM
Hi Atanas,
Thanks for your reply. Is the suggested workaround the same one I linked to? If not, please can you provide the code / link?

Also, has the next release been scheduled yet? If so, roughly when is it due to be available?

Thanks,
Stephen
0
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 11:19 AM
Hello Stephen,

The workaround from that thread should work. In any case you could send me a stripped down version of your implementation at atanas.korchev at telerik.com and I will see what needs to be done.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Stephen
Top achievements
Rank 1
answered on 19 Feb 2010, 03:33 PM
Hi Atanas,
That has indeed fixed sorting, however we have an identical issue with filtering - is there a similar fix for this?

Thanks
Stephen
0
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 03:47 PM
Hello Stephen,

Unfortunately there isn't a simple workaround. The filter expressions are not populated in the filtering UI right now.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Stephen
Top achievements
Rank 1
answered on 22 Feb 2010, 08:48 PM
Hi Atanas
I've looked into working around this myself, and believe I am close to a fix. I've got everything working perfectly with a single FilterDescriptor, but am having issues when attempting to bind a CompositeFilterDescriptor to the grid initially. Is there anything obvious I am doing wrong (it's a little hacky but prototype in progress :)  )?

The Model renders the FilterDescriptors thusly:
public IList<IFilterDescriptor> RenderFilters() 
   IList<IFilterDescriptor> result = new List<IFilterDescriptor>(); 
   foreach(var group in FilterDescriptors.GroupBy(f => f.Member)) 
   { 
        if (group.Count() > 1) 
        { 
            CompositeFilterDescriptor cfd = new CompositeFilterDescriptor(); 
            cfd.LogicalOperator = FilterCompositionLogicalOperator.And; // "Or" is not currently in use 
            foreach (var filter in group) 
            { 
                cfd.FilterDescriptors.Add(filter); 
            } 
            result.Add(cfd); 
        } 
        else 
        { 
            result.Add(group.FirstOrDefault()); 
        } 
    } 
    return result; 

The (relevant) part of the Grid declaration in the View is:

foreach (var filterDescriptor in Model.GroupState.RenderFilters()) 
   if (!grid.DataProcessor.FilterDescriptors.Contains(filterDescriptor)) 
   { 
       grid.DataProcessor.FilterDescriptors.Add(filterDescriptor); 
   } 

The error we are getting is on the grid.Render() call, stack trace:

[NullReferenceException: Object reference not set to an instance of an object.] 
   Telerik.Web.Mvc.UI.<>c__DisplayClass7.<HeaderCellContent>b__4(IFilterDescriptor c) +15 
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source, Func`2 predicate) +183 
   Telerik.Web.Mvc.UI.GridRenderer`1.HeaderCellContent(GridColumn`1 column) +1022 
   Telerik.Web.Mvc.UI.Grid`1.WriteHeaderCell(IGridRenderer`1 renderer, GridColumn`1 column) +96 
   Telerik.Web.Mvc.UI.<>c__DisplayClass18.<WriteHeader>b__16(GridColumn`1 column) +148 
   Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +146 
   Telerik.Web.Mvc.UI.Grid`1.WriteHeader(IGridRenderer`1 renderer) +1081 
   Telerik.Web.Mvc.UI.Grid`1.WriteTable(IGridRenderer`1 renderer) +69 
   Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +324 
   Telerik.Web.Mvc.UI.ViewComponentBase.Render() +83 
   ASP.views_analysis_grid_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in <PROJECTROOT>\Grid.ascx:158 
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256 
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10 
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29 
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59 
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266 
 

Any ideas..?
0
Stephen
Top achievements
Rank 1
answered on 22 Feb 2010, 09:11 PM
Scratch that; After some digging I found that the problem was actually being caused by an earlier "fix" to make the filter icons highlight when active (which I think was taken from elsewhere on this forum).

Changed the following in GridRenderer.cs, HeaderCellContent method from:
IList<IFilterDescriptor> filter = Grid.DataProcessor.FilterDescriptors; 
FilterDescriptor descriptor = filter.SingleOrDefault(c => (c as FilterDescriptor).Member.IsCaseInsensitiveEqual(column.Name)) as FilterDescriptor; 

To:
var filter = Grid.DataProcessor.FilterDescriptors.SelectRecursive(descriptor => 
    CompositeFilterDescriptor compositeDescriptor = descriptor as CompositeFilterDescriptor; 
 
    if (compositeDescriptor != null
    { 
        return compositeDescriptor.FilterDescriptors; 
    } 
 
    return null
}) 
.Where(descriptor => descriptor is FilterDescriptor) 
.Cast<FilterDescriptor>() 
.FirstOrDefault(descriptor => descriptor.Member.IsCaseInsensitiveEqual(column.Name)); 

Fixed. :)
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or