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

Batch EditMode Error adding more than 1 row

1 Answer 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 20 Apr 2021, 04:27 PM

I have a telerik :RadGrid in my project with a Master, Detail configuration. Both Master and Detail tables are have EditMode='Batch'

 I need to dynamically set some columns to readonly on a per row basis. I used BatchEditOpening() to acheive this by setting args._cancel to true on the columns that need to be read only. There is more logic to determine the editability than in the example but the end result is the same: setting args._cancel = true if the field needs to be not editable. 

To replicate the issue:

click the built in 'Add new record' button 3 times. 3 rows are created as expected. 

Then click any where in any of those rows, which should open the row for edit which it does. An error in the telerik function _openCellinEditMode()

It calls this function for the cells that were set to args._cancel = true in the BatchEditOpeining function. The _openCellinEditMode function fails when the following line is executed if (o && $telerik.getElementByClassName(o.cell, e).style.display === "")  because there is no element with the rgBatchContainer class that it is looking for because this cell is no longer editable. 

Is anyone aware of this issue? and is there a workaround / fix for it?

If I take the code out of the  BatchEditOpening function, the error does not occur. It also doesnt occur as each row is added. I have stepped through the code and for each new row added it only calls _openCellinEditMode() for the appropriate editable columns. Then when you click on a cell to edit it will fail by calling the function for a column that has edit cancelled.

 

 

function BatchEditOpening(sender, args) {
                var row = args.get_row();
                //var cell = args.get_cell();
                tableView = args.get_tableView();
                //var column = args.get_column();
                var columnUniqueName = args.get_columnUniqueName();
                args._cancel = false;
 
                var rowstatus = '';
                 
                  if (columnUniqueName == "NotEditableColumn") {
                    args._cancel = true;
                }
 
            }

 

 

_openCellInEditMode: function(q) {
           var u = this;
           var n = q.cell;
           var s = u._getEditorControlsContainer(q.tableView, q.column.get_uniqueName(), n);
           var r = u._getDataControl(s);
           var t = s.parentNode;
           var p = u._getSetCellValue(n);
           var o;
           if (t.tagName.toLowerCase() === "td" || (u._currentlyEditedRow && n.parentNode.id !== u._currentlyEditedRow.id)) {
               if (u._currentlyEditedRow && n.parentNode.id !== u._currentlyEditedRow.id) {
                   t = u._currentlyEditedRow.cells[n.cellIndex];
               }
               o = u._getCellDataToOpenEdit(t);
               if (o && $telerik.getElementByClassName(o.cell, e).style.display === "") {
                   if (!u._updateCellValue(o)) {
                       return false;
                   }
                   u._currentlyEditedCellInfo = null;
               }
           }

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 23 Apr 2021, 09:38 AM

Hi Rick,

To resolve this problem, you will need to close any open cell before opening new ones. You can add this one line at the beginning of the BatchEditOpening event handler.

function OnBatchEditOpening(sender, args) {
    // Close any other cell that are still open for Editing.
    sender.get_batchEditingManager()._tryCloseEdits(sender.get_masterTableView());

    // rest of the logic
}

 

Regards,
Attila Antal
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or