Syntax help - editing a specific grid cell

8 posts, 1 answers
  1. Andrew
    Andrew avatar
    29 posts
    Member since:
    Sep 2010

    Posted 06 Jan 2012 Link to this post

    I need to alter a single cell of a databound grid. Grid is editable, and has single row selection.   Just having trouble getting the syntax right -  given the currently selected row:

    var r = grid.dataItem(grid.select());

    how can I pick a cell (say the 4th column of the grid on the currently selected row), place that cell in edit mode, alter it and force a save.  I have the jist of:

    var g = $("#grid").data("kendoGrid");
        var r = grid.dataItem(grid.select());
        g.editCell( ??? );
        ...
        g.saveChanges();

  2. Answer
    Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 09 Jan 2012 Link to this post

    Hi,

    The easiest way to modify a model's property value you may use the DataSource edit API. Which is demonstrated in the following jsFiddle sample:



    Note that it also demonstrates how to set grid's cell in/out of edit mode.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Andrew
    Andrew avatar
    29 posts
    Member since:
    Sep 2010

    Posted 09 Jan 2012 Link to this post

    Awesome - thanks Rosen.   Switched to the datasource/model approach (which makes more sense anyway, don't know what I was thinking - GRIN).   

    As an aside -  I was wondering why this:

    cell = grid.tbody.find(">tr:first");

    works (selects the first cell in first row of grid) but this:

    cell = grid.tbody.find(">tr:eq(1) >td:eq(1)")

    does not (comes back undefined).   Can you give me a quick syntax of how I might get a cell reference to any (x,y) cell in the grid?
  4. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 10 Jan 2012 Link to this post

    Hi  Andrew,

    Beside the fact that the code in question actually will select the second row and second cell (as the eq function is zero based), it seems ok to me.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Andrew
    Andrew avatar
    29 posts
    Member since:
    Sep 2010

    Posted 10 Jan 2012 Link to this post

    Thanks, Rosen.  Working for me know.   Issue was mine - the column I was attempting to change was set as non-editable in my model/schema (doh!).  

    That reminds me of something I ran across for the possible enhancement list (unless it is in there and I can't tell - GRIN) -  the ability to define a grid COLUMN as non-editable but have it editable via the schema.   The idea is to allow it to be changed at the datasource level but not via the UI.  In my example, I have a user login table in which password data is stored encrypted.  I don't want uses to enter passwords directly, but rather have a separate "set password" custom button that encodes a value and then stores it into the model.  Right now I can only get this to work by allowing the field to be editable...

    Cheers, and thanks for all the help!
  6. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 11 Jan 2012 Link to this post

    Hi,

    I'm afraid that this is not possible. However, you may consider not showing the password in the grid, thus users will not able to edit it through the grid's UI but only through you custom routine.

    Regards,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. carlg
    carlg avatar
    41 posts
    Member since:
    Jun 2012

    Posted 21 Sep 2012 Link to this post

    Above Andrew mentions the following:

    " The idea is to allow it to be changed at the datasource level but not via the UI."


    And then Rosen replies that it is not possible.


    Does anyone know if this functionality has been implemented yet?

  8. Zen
    Zen avatar
    2 posts
    Member since:
    Dec 2015

    Posted 21 Dec 2015 Link to this post

    Is it possible to access editCell using data uid property?

     

Back to Top