This is a migrated thread and some comments may be shown as answers.
Syntax help - editing a specific grid cell
7 Answers 399 Views
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 06 Jan 2012, 10:01 PM
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();

7 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 09 Jan 2012, 02:03 PM
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!
0
Andrew
Top achievements
Rank 1
answered on 09 Jan 2012, 07:06 PM
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?
0
Rosen
Telerik team
answered on 10 Jan 2012, 08:42 AM
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!
0
Andrew
Top achievements
Rank 1
answered on 10 Jan 2012, 03:39 PM
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!
0
Rosen
Telerik team
answered on 11 Jan 2012, 09:43 AM
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!
0
carlg
Top achievements
Rank 1
answered on 21 Sep 2012, 06:15 PM
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?

0
Zen
Top achievements
Rank 1
answered on 21 Dec 2015, 03:16 PM

Is it possible to access editCell using data uid property?

 

Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Andrew
Top achievements
Rank 1
carlg
Top achievements
Rank 1
Zen
Top achievements
Rank 1
Share this question
or