简体   繁体   English

不可编辑的剑道网格 ID

[英]Non editable kendo grid ID

I'm new using kendo grid UI, i'm trying to make a non editable column (when updating) using a simple code :我是使用剑道网格 UI 的新手,我正在尝试使用简单的代码制作不可编辑的列(更新时):

schema: {
   id: 'ID', 
   fields: {
     id: { editable: false }
   }
}

This default schema, makes by default non editable id column, and i can't even create a new row with id .默认情况下,此默认架构使 id 列不可编辑,我什至无法创建带有 id 的新行。 I want to make it non editable (when updating) but i want the possibility to create a row and assign an id from user (when creating).我想让它不可编辑(更新时),但我希望可以创建一行并从用户分配一个 id(创建时)。

Any ideas ?有任何想法吗 ?

Edit :编辑 :

PS : the proprety is not related to only id, it can be on every column (can't update but can create) PS:proprety不仅与id相关,它可以在每一列上(不能更新但可以创建)

The editable required a function instead of a value. editable需要一个函数而不是一个值。

columns: [
    { field: 'value', editable: function () { return false; } }
],

Checkout here: https://dojo.telerik.com/oROJayAd在这里结帐: https : //dojo.telerik.com/oROJayAd

I always doubt about that model editable option.我总是怀疑那个模型editable选项。 It never really worked for me.它从来没有真正对我有用。 It should have something very deep in the setup to make it work which I never realized what it.它应该在设置中具有非常深的东西才能使其工作,而我从未意识到它是什么。 So this is a way to acomplish what you need that I know it indeed works: To cancel the edit event .所以这是一种完成你需要的方法,我知道它确实有效:取消edit事件 Check it out:一探究竟:

edit: function(e) {
    // Cancels a new row
    if (arguments, e.model.isNew()) {
        this.cancelRow(e.container.parent());
    }
    else { // Cancels a cell editing
        this.closeCell(e.container);
    }
}

Demo演示

Now, if you like to add a condition in that event based on what you have set in your model, you can access it within event as well:现在,如果您想根据您在模型中设置的内容在该事件中添加条件,您也可以在事件中访问它:

edit: function(e) {
    let currentColumn = this.options.columns[e.container.index()].field,
        model = this.dataSource.options.schema.model.fields[currentColumn];

    if (model.editable === false) {
        // Cancels a new row
        if (arguments, e.model.isNew()) {
            this.cancelRow(e.container.parent());
        }
        else { // Cancels a cell editing
            this.closeCell(e.container);
        }
    }
}

Demo演示

You can add an option yourself in the model to set if the column can be updated or only created, and handle that information inside the event, canceling the editing whenever you like.您可以自己在模型中添加一个选项来设置列是可以更新还是只能创建,并在事件内处理该信息,随时取消编辑。

This is how I just did it, though there are other ways.我就是这样做的,尽管还有其他方法。

In columns option if you remove the field option from a column it doesn't know from where to bind it.columns选项中,如果您从列中删除field选项,则它不知道从何处绑定它。

Then use the template option to show(bind) the id.然后使用模板选项显示(绑定)id。 Thus making it readonly从而使其成为只读

columns: [
    {
        title: 'Id', width: "40px",
        template: "#= id #",
    },
    ...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM