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

[Solved] Clear selection in Grid Control

4 Answers 149 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.
Gene
Top achievements
Rank 1
Gene asked on 17 Feb 2012, 05:34 PM
I am using the Select option within the Grid Control in order to display related records in a separate Grid Control.
It works Great!

However, if I filter the main grid or move to the next page, the selection persists even though the selected item is no longer visible.

Is there a way to clear the selection after changing page or filter?

Here is the view code for the main grid:

@model MvcApplication3.ViewModels.AdjusterIndexData

@{
    Html.Telerik().Grid(Model.Adjusters)
        .Name("Adjusters")
        .DataKeys(dataKeys => dataKeys.Add(a => a.AdjusterID))
        .Columns(columns =>
        {
            columns.Command(commands => commands.Select()).Title("Select").Width(10);
            columns.Bound(c => c.AdjusterID).Title("Adjuster ID").Width(10);
            columns.Bound(c => c.Last).Width(40);
            columns.Bound(c => c.First).Width(40);
            columns.Bound(c => c.Phone).Width(20); ;
        })
        .Pageable()
        .Sortable()
        .Filterable()
        .Reorderable(r => r.Columns(true))
        .Render();
}

TIA
Gene Stempel

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Feb 2012, 11:37 AM
Hello Gene,

This can be achieved by returning data for the related Grid only if the currently displayed data in the master Grid contains the sent ID. To avoid duplicating queries, you could use Custom Binding for the master Grid.
I attached a sample project which demonstrates this scenario. I hope it helps.

All the best,
Daniel
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Gene
Top achievements
Rank 1
answered on 16 Mar 2012, 09:03 PM
Hi Daniel,

Sorry for the late response. I appreciate you taking the time to answer my question. Thank you!
0
Gene
Top achievements
Rank 1
answered on 10 Apr 2012, 04:58 PM
Hi Daniel,

I have been using your suggestion to enable custom binding to great success. Thank you.

I have run into something odd though. In the controller is a block of code as follows:

            if (command.PageSize == 0)
            {
                command.PageSize = 10;
                command.Page = 1;
            }

If I change the PageSize from 10 to 20 above, the pages do show 20 items per page, but the pagination controls still behave as though there are only 10. That is, on the bottom right it still says "1-10 of 99999". Also, if I select the "Last Page" link, the grid is empty.

Any thoughts?
0
Daniel
Telerik team
answered on 12 Apr 2012, 08:17 PM
Hello Gene,

The page size is set to ten in the example as this is the default value. If you want to use different size, you should also set it in the Grid's Pagable configuration e.g.

int gridPageSize = 20;
ViewData["pageSize"] = gridPageSize;
if (command.PageSize == 0)
{
    command.PageSize = gridPageSize;
    command.Page = 1;
}
.Pageable(settings=>settings.PageSize((int)ViewData["pageSize"]).Total((int)ViewData["total"]))


Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Gene
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Gene
Top achievements
Rank 1
Share this question
or