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

RadGrid.SelectedItems does not contain the correct rows

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 31 May 2017, 02:31 PM

I have a Grid which has a GridClientSelectColumn in it and multirow selection enabled. Because I wanted to be able to be able to select rows by clicking anywhere on the row rather than just hitting the tiny checkbox I am using the JavaScript below for these events:

 

Then as part of the code behind for a button click I am doing a RadGrid1.SelectedItems to get all the highlighted/Selected rows. However if I select a few rows and then deselect some of them then RadGrid1.SelectedItems is returning the unselected rows still?

 

foreach (GridDataItem selectedRow in RadGrid1.SelectedItems)
            {
                Bookings.bookingRequest bookRow = new Bookings.bookingRequest();
                bookRow.empID = txtEmpId.Text;
                bookRow.keepCurrent = radioKeepBookings.SelectedValue;
                bookRow.woNo = int.Parse(selectedRow.GetDataKeyValue("woNo").ToString());
                bookRow.seqNo = selectedRow.GetDataKeyValue("seqNo").ToString();
 
                bookings.Add(bookRow);
            }

var originalClickedRowState = null;
var clickedRow = null;
 
function rgGrid_OnRowClick(sender, args) {
    clickedRow = args.get_gridDataItem();
    originalClickedRowState = args.get_gridDataItem().get_selected();
}
 
function rgGrid_OnRowDeselecting(sender, args) {
    if (clickedRow != null && clickedRow != args.get_gridDataItem()) {
        args.set_cancel(true);
    }
}
 
function rgGrid_OnRowSelecting(sender, args) {
    if (clickedRow == args.get_gridDataItem() && originalClickedRowState) {
        args.set_cancel(true);
        originalClickedRowState = null;
        clickedRow = null;
    }
}
 
function rgGrid_OnRowSelected(sender, args) {
    originalClickedRowState = null;
    clickedRow = null;
}

 

<ClientEvents<br>                                        OnRowClick="rgGrid_OnRowClick"<br>                                        OnRowSelecting="rgGrid_OnRowSelecting"<br>                                        OnRowDeselecting="rgGrid_OnRowDeselecting"<br>                                        OnRowSelected="rgGrid_OnRowSelected" />

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 05 Jun 2017, 05:40 AM
Hi Max,

You can achieve this requirement using the following approach:
http://www.telerik.com/support/code-library/get-selected-items-through-all-pages#kht8vWCthkS9M1nSFAY8yg

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or