jQuery 禁用剑道网格中的编辑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14402953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:32:54  来源:igfitidea点击:

Disable editing in kendo grid

jqueryasp.net-mvcrazorkendo-ui

提问by user1870358

I am trying make the an editable grid to uneditable depend on conditions.

我正在尝试根据条件将可编辑网格变为不可编辑。

I have tried in jquery as below

我在 jquery 中尝试过如下

var $grid = &("#gridName").data("kendogrid");
Var model = $grid.datasource.at(1);
if(model)
  model.field["cell"].editable = false;

but here the 'model' is getting undefined.

但这里的“模型”变得不确定。

also tried $grid.data() and then looping through the grid, but the cells are not getting uneditable they are still editable.

还尝试了 $grid.data() 然后循环遍历网格,但单元格并没有变得不可编辑,它们仍然可以编辑。

Can anyone please let me know how can I make this work.

任何人都可以让我知道我如何才能完成这项工作。

采纳答案by user1870358

Issue is resolved.

问题已解决。

var $grid = &("#gridName").data("kendoGrid");
var len= &("#gridName").data("kendoGrid tbody tr").length();
for(i=0;i<=len ; i++)
{
var model = $grid.datasource.at(i);
if(model)
  model.fields["cell"].editable = false;
}

回答by OnaBai

You have some typographic errors...

你有一些排版错误...

Try this instead:

试试这个:

var $grid = $("#gridName").data("kendoGrid");
var model = $grid.dataSource.at(1);
if (model)
    model.fields["cell"].editable = false;
  1. Line 1. In datait is kendoGridand not kendogrid.
  2. Line 2. In modelit is varand not Var
  3. Line 4. It is fieldsand not field
  1. 第 1 行。data其中是kendoGrid而不是kendogrid
  2. 第 2 行。model里面是var而不是Var
  3. 第 4 行。它是fields和不是field

EDIT:If you want to change "cell"column to not editable, simply do:

编辑:如果要将"cell"列更改为不可编辑,只需执行以下操作:

var $grid = $("#gridName").data("kendoGrid");
$grid.dataSource.at(0).fields["cell"].editable = false;

You just need to change it to one row since the model is shared by all rows in the grid.

您只需将其更改为一行,因为该模型由网格中的所有行共享。

See it running in JSFiddle here http://jsfiddle.net/OnaBai/GuyPa/

在这里查看它在 JSFiddle 中运行http://jsfiddle.net/OnaBai/GuyPa/

回答by hamzeh.hanandeh

to disable cell editing:

禁用单元格编辑:

 var len = $("#gridName").find("tbody tr").length;
    for(var i=0;i<=len ; i++)
    {
        var model = $("#gridName").data("kendoGrid").dataSource.at(i);
        if (model) {//field names
            model.fields["DueDateStr"].editable = false;
            model.fields["TotalAmount"].editable = false;
            model.fields["IsPercentage"].editable = false;
        }

    }

to disabled check box control's which it in the template:

禁用模板中的复选框控件:

$.map($("#gridName").find("input:checkbox"),
        function (item) {
            $(item).attr('disabled', 'disabled');
        }
    );

to remove command buttons like delete button:

删除命令按钮,如删除按钮:

 var rows = $('#gridName tbody tr');
    $.map(rows, function (row) {
        //cell buttons index
        row.cells[4].innerHTML = "";

    });

to hide toolbar grid:

隐藏工具栏网格:

$("#gridName .k-grid-toolbar").hide();

回答by moomoo

If you're using "incell" edit mode, the grid has an "edit" event you could use to immediately close the cell.

如果您使用“incell”编辑模式,网格有一个“编辑”事件,您可以使用它立即关闭单元格。

$("#grid").kendoGrid({

  ...

  edit: function(e) {
      if ( ... ) {
          this.closeCell();
      }
  }

  ...

});

A more powerful approach would be to subclass the kendoGrid and override the editCell and/or editRow methods. Then you can do whatever you want. Look herefor info on subclassing kendo widgets.

更强大的方法是将 kendoGrid 子类化并覆盖 editCell 和/或 editRow 方法。然后你可以为所欲为。 在此处查看有关子类化剑道小部件的信息。

回答by Parthiv Pandya

for(i=0;i<=$("#grid").find("tbody tr").length ; i++)
{ 
  var model = $("#grid").data("kendoGrid").dataSource.at(i);
  if(model)
  {
      model.fields[$("#grid").data("kendoGrid").columns[i].field].editable = false;    
  }
}

http://jsfiddle.net/parthiv89/qwtyLmhk/

http://jsfiddle.net/parthiv89/qwtyLmhk/

I hope this works well..if works then don't forget to vote me..

我希望这很好用..如果有效,请不要忘记投票给我..