Customized multiple row selections in Devextreme Datagrid with dxRadiogroup as a Custom Column Field
I am using Devextreme jquery datagrid with paging options implemented that involves setting permissions for user. The target here is to update the datasource and dxRadiogroup values when multiple rows are selected.
This is a modified way to handle the multiple selections taken as a refrence from https://www.devexpress.com/Support/Center/Question/Details/T534792/how-to-change-dxradiogroup-value-at-runtime(and some similar posts). The solution presented in these does not resolve the issue if paging is used.
Taking the above screenshot as an example, our target is on click of “Allow” for user in 3rd row, the value for selected user in row 2 on page 2 and selected user in row 3rd on page 3 should change to “Allow”.
Here is the snippet of code that resolves the radio group selection issue:
In general case when no rows are selected, and when we change the value from radiogroup for allow deny permission, we can simply update the value in datasource for that specific row field by simply using
When multiple rows are selected and on change of one of the selected row dxRadioGroup, other selected rows dxRadioGroup values must be modified corresponding to changed dxRadioGroup value.
But in the case when multiple rows are selected but we are modifying the radiogroup value from unselected row, and this should not modify other radiogroup values - to ensure this condition we can apply the check if the current modified row is Selected or not by using the row key.
So we need to fire the statement 1 to ensure even if we are try to edit the unselected row radiogroup when multiple rows are selected it should not fire the multiple row selection case but just update only the corresponding row in datasource.
The step mentioned as “Update radiogroup values” modifies the UI radiogroup values but does not update the datasource as in this case onValueChanged() event is not fired.
Second issue with this is radiogroup values are modified only in the current page. So if we move to another page the change will not be reflected for the different page selected rows. This happens because when we are at one page, then only the rows related to current page index are loaded. When we move to different page, rows are loaded freshly from the datasource.
Datasource can be updated by the code lines mentioned under “Update datasource” . For this we can simply get the row index from the datasource by processing selectedRowsData obtained from the grid and update the “allowed” column field value based on the . This will not only Updating the datasource will automatically resolve the second issue(as moving the next page loads the fresh rows from the datasource.)
Step ‘refresh grid’ is required to refresh the instance of grid, as on datasource update, selectedRowsdata of grid becomes inconsistent , and when we move from one page to next, sometimes rows appear as unselected(although selected rows data is maintained by the datagrid).