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

BatchEditingManager.changeCellValue

5 Answers 286 Views
Grid
This is a migrated thread and some comments may be shown as answers.
أشرف
Top achievements
Rank 1
أشرف asked on 10 Dec 2013, 11:48 AM
Greetings,

As I mentioned in a previous post, the batch mode grid doesn't store its data in an easily accessible JavaScript data structure, and rather, uses the DOM as a data store, and we want an easy API to read and write cell values.

The BatchEditingManager has getCellValue and changeCellValue methods, but I think they are unreliable in some situations.

changeCellValue doesn't write directly to the table cell. It opens the cell for editing, sets the value, then closes the cell. This behaviour is not acceptable when setting a value to a cell of the currently being edited row. When I call the function, the whole row is closed.
I have scenarios in which I want to change the value of a read only cell when the row is open. For example, I have a grid with two columns, code, and name, with the name cell containing a search box that sets the value of the code cell when the user chooses an item.

At last, I had to write my setCellValue function as follows:

Edge.UI.GridExtensions.setCellValue = function (columnUniquName, dataItem, value)
{
    var tableView = dataItem.get_owner(),
        cell = tableView.getCellByColumnUniqueName(dataItem, columnUniquName);
 
    if(!cell)
        return false;
 
    var valueDiv = cell.querySelector(".rgBatchContainer"),
        valueTextElement = valueDiv? valueDiv.childNodes[0]: null;
 
    if(valueTextElement)
        valueTextElement.textContent = value;
    else if(valueDiv)
        valueDiv.innerHTML = value;
    else
        cell.innerHTML = value;
 
    return true;
}

Which is hacky because it depends on the internal undocumented structure of the grid.
I hope a better alternative will be provided in the future.

5 Answers, 1 is accepted

Sort by
0
أشرف
Top achievements
Rank 1
answered on 10 Dec 2013, 01:47 PM
getCellValue has the same trait. It calls _getCellDataToOpenEdit then returns the value based on the return. If _getCellDataToOpenEdit returns null it returns null.

I don't have a way to read read-only cells, and have to write my own getCellValue.
0
Konstantin Dikov
Telerik team
answered on 13 Dec 2013, 09:37 AM
Hello Ashraf,

The behavior you are describing is expected and is made that way by design. Please note that getCellValue() function is internal for the batchEditingManager and its main purpose is to retrieve values from editable cells. 

If you need to get a value from a cell with ReadOnly property of the column set to "true", you could use the following: cell.innerHTML.

Regarding the other issue for changing cell value when the row is opened for editing, you should use the approach that you have shown, since this is the only way to avoid the closing of the row after calling changeCellValue().


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
أشرف
Top achievements
Rank 1
answered on 15 Dec 2013, 08:26 AM
If it's internal, why wasn't it named _getCellValue?
0
أشرف
Top achievements
Rank 1
answered on 15 Dec 2013, 08:32 AM
The merit of using your API is that you encapsulate the DOM structure details in it. If you later change the structure of the grid or the CSS class names (like rgNoRecords for example) I'll need to revise all my relevant code, which will be a factor making us refrain of upgrading to new releases.
0
Konstantin Dikov
Telerik team
answered on 18 Dec 2013, 02:53 PM
Hello Ashraf,

What I meant to say regarding the getCellValue() was that it is relevant only when Batch edit mode is used.

Now moving to your concerns about future changes in the RadGrid structure. Please have in mind that such changes are considered as breaking changes and we are doing our best to avoid them in any way possible. We are aware that many of our clients have build custom solutions based on the current structure of our RadControls and that any change on our end could have huge impact on their projects.

As a conclusion, I could only assure you that it is not likely that such changes will appear in the future.


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
أشرف
Top achievements
Rank 1
Answers by
أشرف
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or