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

Row selection in batchedit mode

1 Answer 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
miksh
Top achievements
Rank 1
Iron
miksh asked on 09 Jul 2014, 04:21 PM
We seem to found a cosmetic glitch in a grid with BatchEdit mode and
<ClientSettings Selecting-AllowRowSelect="true" />
<BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />

When an existing row is selected it is highlighted by applying <tr class="rgAltRow rgSelectedRow">
When a new record is added and activated the selection stays on the row selected before. You have to click on the new row outside of any input controls (e.g. texboxes) to make this row selected. However, when you click to any input in existing rows then that row becomes selected.
It's is a little inconsistent.

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 14 Jul 2014, 10:52 AM
Hello Miksh,

What you are describing is the default and expected behavior of RadGrid. When you enable row selection of RadGrid, when you click on a row, it will become selected. Since you are setting the Batch edit mode to use the Click event for opening editing, when you click on a row, this will open the row for edit, but will also select the row (due to the Click event). However, when you click on the Add new record button, the newly added row will become active, but since you are not clicking on that row, it will not be selected.

Nevertheless, you could apply custom logic for selecting the newly added rows with the following JavaScript, where the client-side OnBatchEditOpened and OnBatchEditClosed events are handled:
<telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
        var shouldSelect = true;
        function editOpened(sender, args) {
            if (shouldSelect) {
                if (args.get_tableView().get_selectedItems().length > 0) {
                    args.get_tableView().get_selectedItems()[0].set_selected(false); //if the multirow selection is disabled
                }
 
                shouldSelect = false;
                var dataItems = args.get_tableView().get_dataItems();
                var rowID = args.get_row().id;
                for (var i = 0; i < dataItems.length; i++) {
                    if (dataItems[i].get_element().id == rowID) {
                        dataItems[i].set_selected(true);
                    }
                }
            }
        }
 
        function editClosed(sender, args) {
            shouldSelect = true;
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
        <BatchEditingSettings EditType="Row" OpenEditingEvent="DblClick" />
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true">
        <ClientEvents OnBatchEditOpened="editOpened" OnBatchEditClosed="editClosed" />
    </ClientSettings>
</telerik:RadGrid>

Please give the above a try and see if the result meets your requirement.


Regards,
Konstantin Dikov
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
miksh
Top achievements
Rank 1
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or