Greetings,
I'll try to be clear as possible in describing this problem as I couldn't catch its cause until I did long debugging inside Rad controls' code.
What I'm trying to create is a serial column (1, 2, 3, …) that keeps its proper serialing with the user deleting from and adding to the grid in batch mode.
The logic is very simple. I added a handler to the RowCreated event as follows:
The relevant part is the line marked with bold and italic (dataItems = tableView.get_dataItems())
Here's the sequence I do to reproduce the problem:
I'll try to be clear as possible in describing this problem as I couldn't catch its cause until I did long debugging inside Rad controls' code.
What I'm trying to create is a serial column (1, 2, 3, …) that keeps its proper serialing with the user deleting from and adding to the grid in batch mode.
The logic is very simple. I added a handler to the RowCreated event as follows:
grid.add_rowCreated(
function
(sender, args)
{
var
item = args.get_item();
if
(Edge.UI.GridExtensions.isNewRow(item))
Edge.UI.GridExtensions.setCellValue(item, uniqueName, Edge.UI.GridExtensions.SerialColumn.getMaxSerialValue(tableView, uniqueName) + 1);
});
Edge.UI.GridExtensions.SerialColumn.getMaxSerialValue =
function
(tableView, uniqueName)
{
var
max = Number.NEGATIVE_INFINITY,
dataItems = tableView.get_dataItems();
if
(dataItems && dataItems.length)
{
for
(
var
i = dataItems.length; i--;)
{
var
value = parseInt(Edge.UI.GridExtensions.getCellValue(dataItems[i], uniqueName));
if
(value > max)
max = value;
}
}
return
max === Number.NEGATIVE_INFINITY ? 0 : max;
}
The relevant part is the line marked with bold and italic (dataItems = tableView.get_dataItems())
Here's the sequence I do to reproduce the problem:
- I start with an empty grid, then click the "Add New" button.
- The button calls BatchEditingManager.addNewRecord which in turn calls GridTableView.createItem.
- createItem creates the TR element and appends it to the DOM and creates a GridDataItem object for it.
- Then, near the end of the method body, come two lines of code who cause the problem:
p._owner.raise_rowCreated(
new
Telerik.Web.UI.GridDataItemEventArgs(n,
null
));
Array.insert(e, k, d);
if
(
this
._dataItems.length > 0 || (
this
._cachedItems &&
this
._cachedItems.length > 0)) {
return
this
._dataItems;
}
var
o = ($telerik.isOpera) ?
this
.get_element() :
this
.get_element().tBodies[0];
var
n = o.rows;
for
(
var
c = 0, k = n.length;
c < k;
c++) {
…
this
._owner.raise_rowCreating(
new
Sys.EventArgs());
…
if
(!b) {
b = $create(Telerik.Web.UI.GridDataItem, {_owner:
this
,_data: a},
null
,
null
, m);
}
…
this
._dataItems[
this
._dataItems.length] = b;
this
._owner.raise_rowCreated(
new
Telerik.Web.UI.GridDataItemEventArgs(m,
null
));
}
- After all that code executes, the _dataItems array now have two objects for the same TR element (one created by createItem and the other created by the get_dataItems accessor), if I remove the single grid row using BatchEditingManager.deleteRecord the grid remains with an orphan GridDataItem object.
After this, the grid stops working. When I try adding new lines, an exception erupts. I don't know certainly the cause, but it should be because of the orphan item.
After the description of the problem, I'd like to say that some accessors in the Rad controls code involve a lot of work which shouldn't be the nature of accessors. I have some places where get_dataItems raises exceptions, and I had no means to avoid but a nasty dummy try/catch
try
{
gridDataItems =
this
.tableView.get_dataItems();
}
catch
(dummy)
{ }