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

[Solved] RadGrid Not Deselecting Previously Selected Rows

2 Answers 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua Owen
Top achievements
Rank 1
Joshua Owen asked on 30 Sep 2009, 03:27 PM
Hello,

I am using a RadGrid with clientside binding to a WCF service and it is not deselecting previously selected rows as the page changes.  I have written script to keep track of selected rows in JavaScript, but when changing pages, it keeps the row selected.  For example if I select row 3, and switch to the next page, the new row 3 is still selected.

What is the event that fires after data is bound on the client side.  I assume I can write a script to iterate over the grid's data and select and unselect rows.

Here is the code I have so far:
var selected = {};
        function RadGrid1_RowSelected(sender, args) {
            var ResourceKey = args.getDataKeyValue("resourceKey");
            if (!selected[ResourceKey]) {
                selected[ResourceKey] = true;
            }
            updateSelected();
        }
        function RadGrid1_RowDeselected(sender, args) {
            var ResourceKey = args.getDataKeyValue("resourceKey");
            if (selected[ResourceKey]) {
                selected[ResourceKey] = null;
            }
            updateSelected();
        }

Regards,
Josh

2 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 02 Oct 2009, 01:59 PM
You could try this line of code:

RadGrid1.SelectedItems[i].Selected = false

Where "i" would be the row you are trying to deselect - see if this helps you out.
0
Joshua Owen
Top achievements
Rank 1
answered on 02 Oct 2009, 02:04 PM
I actually figured it out the other day, sorry for not posting the solution sooner.  This (with my code above) will handle the row selection, and it will also add a checkbox to the ClientSelectColumn when the page size changes (the control doesn't do this for client side binding to a web service):

 function RadGrid1_RowDataBound(sender, args) {
            /* Create Checkboxes on Page Resize */
            var cell = sender.get_masterTableView().getCellByColumnUniqueName(args.get_item(), "ClientSelectColumn");
            var input = $telerik.findElement(cell, "ClientSelectColumnSelectCheckBox");
            if (!input) {
                cell.innerHTML = String.format("<input type='checkbox' id='{0}' />", "ClientSelectColumnSelectCheckBox");
            }
            /* Persist row selections across pages */
            var key = sender.get_masterTableView().getCellByColumnUniqueName(args.get_item(), "resourceKey").innerHTML;
            if (selected[key]) {
                args.get_item().set_selected(true);
            } else {
                args.get_item().set_selected(false);
            }
        }


Regards,
Josh
Tags
Grid
Asked by
Joshua Owen
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Joshua Owen
Top achievements
Rank 1
Share this question
or