Javascript 禁用剑道网格的一列
我有一个应用程序,其中我有一个KendoGrid,其中有两列。在第一列中,我根据条件添加了一个标签。现在,我想为每行禁用此列。我使用Incell编辑来编辑列的数据,因此,当我在通过Incell编辑KendoGrid的同时单击第一列时,它将被删除必须禁用,否则不能编辑。 我的代码如下:Javascript 禁用剑道网格的一列,javascript,jquery,asp.net-mvc,kendo-ui,kendo-grid,Javascript,Jquery,Asp.net Mvc,Kendo Ui,Kendo Grid,我有一个应用程序,其中我有一个KendoGrid,其中有两列。在第一列中,我根据条件添加了一个标签。现在,我想为每行禁用此列。我使用Incell编辑来编辑列的数据,因此,当我在通过Incell编辑KendoGrid的同时单击第一列时,它将被删除必须禁用,否则不能编辑。 我的代码如下: @(Html.Kendo().Grid(Model) .Name("Remark") .TableHtmlAttributes(new { style = "heig
@(Html.Kendo().Grid(Model)
.Name("Remark")
.TableHtmlAttributes(new { style = "height:20px; " })
.Columns(columns =>
{
columns.Bound(p => p.RemarkID).Hidden(true).ClientTemplate("#= RemarkID#" + "<input type='hidden' class='RemarkID' value='#=RemarkID#' />");
//columns.Bound(p => p.RemarkCode).Title("Remark Code").Width(3).ClientTemplate("#= RemarkCode#" + "<input type='hidden' class='RemarkCode' value='#=RemarkCode#' />");
columns.Bound(p => p.RemarkDescription).Title("Type").Width(10).ClientTemplate("#= RemarkDescription#" + "<input type='hidden' class='RemarkDescription' value='#=RemarkDescription#' />");
columns.Bound(p => p.Remark).Title("Remark").Width(50).ClientTemplate("#= Remark#" + "<input type='hidden' class='Remark' value='#=Remark#' />");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Navigatable()
.Sortable()
.Scrollable(scr => scr.Height(200))
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
model.Id(p => p.RemarkID)
)
.Create("Editing_Create", "Grid")
.Read("Remark_Read", "Document")
.Update("Editing_Update", "Grid")
.Destroy("Editing_Destroy", "Grid")
)
)
$(".AddNewRemark").click(function () {
//grid.addRow();
var dataSource = grid.dataSource;
var total = dataSource.data().length;
dataSource.insert(total, {});
dataSource.page(dataSource.totalPages());
grid.editRow(grid.tbody.children().last());
var it = $(this).text().trim();
$("#RemarkDescription").val(it);
$("#RemarkDescription").attr('readonly', 'readonly');
grid.dataSource._data[total].RemarkDescription = it;
for(var i=0;i<=total;i++){
grid.dataSource.at(i).fields["RemarkDescription"].editable=false;
}
});
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>
@(Html.Kendo().Grid(模型)
.姓名(“备注”)
.TableHtmlAttributes(新的{style=“height:20px;”})
.列(列=>
{
columns.Bound(p=>p.RemarkID).Hidden(true).ClientTemplate(“#=RemarkID#“+”);
//columns.Bound(p=>p.RemarkCode).Title(“备注代码”).Width(3).ClientTemplate(“#=RemarkCode”#“+”);
columns.Bound(p=>p.RemarkDescription).Title(“Type”).Width(10).ClientTemplate(“#=RemarkDescription”#“+”);
columns.Bound(p=>p.Remark).Title(“Remark”).Width(50).ClientTemplate(“#=Remark#”+”);
})
.Editable(Editable=>Editable.Mode(GridEditMode.InCell))
.Navigatable()
.Sortable()
.可滚动(scr=>scr.高度(200))
.Scrollable()
.DataSource(DataSource=>DataSource
.Ajax()
.Batch(真)
.ServerOperation(错误)
.Events(Events=>Events.Error(“错误处理程序”))
.Model(Model=>
model.Id(p=>p.RemarkID)
)
.Create(“编辑”“创建”“网格”)
.Read(“备注”“文件”)
.Update(“编辑更新”、“网格”)
.Destroy(“编辑、销毁”、“网格”)
)
)
$(“.AddNewRemark”)。单击(函数(){
//grid.addRow();
var dataSource=grid.dataSource;
var total=dataSource.data().length;
insert(总计,{});
page(dataSource.totalPages());
editRow(grid.tbody.children().last());
var it=$(this.text().trim();
$(“#RemarkDescription”).val(it);
$(“#RemarkDescription”).attr('readonly','readonly');
grid.dataSource.\u data[total].remarkscription=it;
对于(var i=0;i试试这个,
这只是一个例子
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>
$(文档).ready(函数(){
var crudServiceBaseUrl=”http://demos.kendoui.com/service",
dataSource=新建kendo.data.dataSource({
运输:{
阅读:{
url:crudServiceBaseUrl+“/Products”,
数据类型:“jsonp”
},
更新:{
url:crudServiceBaseUrl+“/Products/Update”,
数据类型:“jsonp”
},
销毁:{
url:crudServiceBaseUrl+“/Products/Destroy”,
数据类型:“jsonp”
},
创建:{
url:crudServiceBaseUrl+“/Products/Create”,
数据类型:“jsonp”
},
parameterMap:功能(选项、操作){
if(操作!=“读取”&&options.models){
返回{models:kendo.stringify(options.models)};
}
}
},
批次:对,
页面大小:20,
模式:{
型号:{
id:“产品id”,
字段:{
ProductID:{可编辑:false,可空:true},
产品名称:{验证:{必需:true},可编辑:false,},
单价:{type:“number”,验证:{required:true,min:1},
中止:{type:“boolean”},
UnitsInStock:{type:“number”,验证:{min:0,必需:true}
}
}
}
});
$(“#网格”).kendoGrid({
数据源:数据源,
可导航:是的,
pageable:对,
身高:430,
工具栏:[“创建”、“保存”、“取消”],
栏目:[
“产品名称”,
{字段:“单价”,标题:“单价”,格式:{0:c},宽度:110},
{字段:“单位库存”,标题:“库存单位”,宽度:110},
{字段:“中断”,宽度:110},
{命令:“销毁”,标题:,宽度:90}],
可编辑:真
});
});
如果要禁用Incell编辑网格中的一列,请对该列使用可编辑:false
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>
如果对网格列使用editable:false
属性,并且希望在该网格中添加新项,则应始终禁用第一列且我不知道Razor语法的ans。在要禁用的特定列的架构声明中将editable设置为false
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>