Programmatically setting column to editable

4 posts, 0 answers
  1. donig
    donig avatar
    8 posts
    Member since:
    Jun 2012

    Posted 18 Dec 2013 Link to this post

    I have a grid data model defined like this:

                    var griddatamodel = kendo.data.Model.define({
                        id: "RequestId",
                        fields: {
                            Status: { type: "string", editable: false },
                            Priority: { type: "number", editable: true, validation: { min: 1, max: 9999 } }
                        }
                    });

    The datasource retrieves the data based on a few drop down lists. I have a function that returns an CanChangePriority Boolean based on the values of the drop down lists. I want to be able to make the Priority field editable depending on the CanChangePriority Boolean, and update the editable flag as the drop down selection is changed. Is there a way to do that?

    Doni
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 19 Dec 2013 Link to this post

    Hello Doni,

    Changing the editable option during run-time is not supported, however you could use another approach to achieve the same functionality. For example you could use the Grid's edit event handler to check which cell you are trying to edit and if the conditions are met - to close it. Here is an example that demonstrates the above functionality.

    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. donig
    donig avatar
    8 posts
    Member since:
    Jun 2012

    Posted 19 Dec 2013 Link to this post

    Thanks. Hooking the edit event works. I'm using incell editing mode, and can tell which column is being edited using the e.container.context.cellIndex property.

    Is there a way to get the name of the column being edited? Using cellIndex works, but if columns get moved, then I have to update the code? I would prefer to get the edited column name directly.

    Doni
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 20 Dec 2013 Link to this post

    Hi Doni,

    Yes, you can use the currently edited cell index to get the name of the field it's bound to. For example:  
    edit: function(e){
          var grid = this;
          var fieldName = grid.columns[e.container.index()].field;
    }

    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready