BatchEditingManager.changeCellValue

6 posts, 0 answers
  1. Ashraf Sabry
    Ashraf Sabry avatar
    88 posts
    Member since:
    Jan 2011

    Posted 10 Dec 2013 Link to this post

    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.
  2. Ashraf Sabry
    Ashraf Sabry avatar
    88 posts
    Member since:
    Jan 2011

    Posted 10 Dec 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1794 posts

    Posted 13 Dec 2013 Link to this post

    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.
  5. Ashraf Sabry
    Ashraf Sabry avatar
    88 posts
    Member since:
    Jan 2011

    Posted 15 Dec 2013 Link to this post

    If it's internal, why wasn't it named _getCellValue?
  6. Ashraf Sabry
    Ashraf Sabry avatar
    88 posts
    Member since:
    Jan 2011

    Posted 15 Dec 2013 Link to this post

    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.
  7. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1794 posts

    Posted 18 Dec 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017