3
A
回答
7
开箱即用,没有允许控制每行版本的功能。当该行尝试编辑时,您可以执行的是退出编辑。
有一个事件edit
一旦一个单元格进入编辑模式,就会被触发。你能做的就是一旦你发现你的条件是真的就关闭那个单元格。
例子:我们有如下定义schema
网格:
schema : {
model: {
fields: {
Id : { type: 'number' },
FirstName: { type: 'string' },
LastName : { type: 'string' },
City : { type: 'string' }
}
}
}
我们不希望让行这City
是Seattle
版。该edit
处理程序应定义为:
var grid = $("#grid").kendoGrid({
dataSource: ds,
editable : true,
edit : function (e) {
// e.model contains the model corresponding to the row that is being edited.
var data = e.model;
if (data.City === "Seattle") {
// Close the cell (exit edition mode)
this.closeCell();
}
e.preventDefault();
},
pageable : true,
columns :
[
{ field: "FirstName", width: 90, title: "First Name" },
{ field: "LastName", width: 90, title: "Last Name" },
{ field: "City", width: 100 }
]
}).data("kendoGrid");
的问题是电池后实际处于编辑模式,以便关闭可能会产生一些闪烁,但在大多数情况下,它应该工作edit
处理函数。
第二个选项是定义网格为不可编辑,并调用editCell
如果手动条件为真:
在这种情况下可以定义grid
为:
var grid = $("#grid").kendoGrid({
dataSource: ds,
editable : false,
pageable : true,
columns :
[
{ field: "FirstName", width: 90, title: "First Name" },
{ field: "LastName", width: 90, title: "Last Name" },
{ field: "City", width: 100 }
]
}).data("kendoGrid");
,然后定义一个click
处理器的单元格:
grid.tbody.on("click", "td", function (e) {
// Close any possible cell already in edit mode
grid.closeCell();
// Find data corresponding to clicked cell
var data = grid.dataItem($(e.target).closest("tr"));
// Check condition
if (data.City !== "Seattle") {
// Enter edition mode
grid.editCell(e.target);
}
});
我在哪里检索data
为row
对应于所点击的表格单元以及对条件的检查。如果条件匹配,然后我打开单元格。
尽管这没有闪烁,但它并不是我的首选,因为您需要小心地触发save
以保存单元格,尽管您说网格不可编辑,但您正在编辑它。
运行第一个实现此例如:http://jsfiddle.net/OnaBai/NWw7T/ 和第二的位置:http://jsfiddle.net/OnaBai/NWw7T/1/
对于除“盒内”最简单的实现相同功能创建一个自定义的编辑按钮,如果控制的其他版本模式一排应该或不应该进入编辑模式。
0
对我来说,我想阻止用户在尝试添加新行时双击其他行。举个例子,这个代码:
var IDS = {
myGrid: "#my-grid",
addRowBtn: "#add-btn",
deleteRowBtn: "#delete-btn",
saveRowBtn: "#save-btn",
cancelRowBtn: "#cancel-btn",
};
var Grids = {
MyGrid: null,
//...
};
然后在初始化函数创建一个事件处理程序的响应双击事件:
function initMyGrid() {
$(IDS.myGrid).kendoGrid({
selectable: true,
scrolable: true,
sortable: false,
columns: [
{ field: "FirstName", title: "First Name", width: "20%", attributes: { tabindex: "1" } },
{ field: "LastName", title: "Last Name", width: "60%", attributes: { tabindex: "2" } }
]
});
//...
Grids.MyGrid = $(IDS.myGrid).data('kendoGrid');
Grids.MyGrid.element.on("dblclick", "tbody>tr>td:not(.k-edit-cell)", "dblclick", function(e) {
Grids.MyGrid.editCell($(this));
});
}
然后我创建了PageState值测试:
var PageState = {
// ...
AddingRow: false
};
因此,当用户点击一个按钮来添加一个新行,我阻止他们点击编辑任何其他行:
function addNewRow() {
PageState.AddingRow = true;
Grids.MyGrid.element.on("dblclick", "tbody>tr>td:not(.k-edit-cell)", "dblclick", function(e) {
if (PageState.Selected.RowId != null && PageState.Selected.RowId != "") {
Grids.RulesGrid.closeCell();
}
});
// ...
}
而且,只要用户保存行或抵消增加一个新行的,我重新启用双击事件:
function saveRow() {
PageState.AddingRow = false;
// Allow user to edit other records now
Grids.MyGrid.element.on("dblclick", "tbody>tr>td:not(.k-edit-cell)", "dblclick", function(e) {
Grids.MyGrid.editCell($(this));
});
// ...
}
HTH。
相关问题
- 1. Kendo Grid内嵌编辑DateTime
- 2. kendo ui grid编辑/导航
- 3. Kendo Grid内联编辑
- 4. Kendo UI Grid编辑问题
- 5. Kendo Grid内联编辑Kendo DataPicker
- 6. Kendo Ui Grid禁用按钮编辑内联模式时
- 7. Kendo Grid内联编辑禁用下拉选项
- 8. Kendo Grid获取你正在编辑的行编辑功能
- 9. 禁用Kendo Grid的一列
- 10. 在Kendo Grid中,我如何在进行内联编辑时禁用拖动?
- 11. Kendo Grid(删除,编辑按钮)
- 12. Kendo Grid jQuery - 可编辑单元格
- 13. Kendo Grid取消编辑事件
- 14. 双击编辑Kendo Grid incell或内联编辑
- 15. Kendo UI Grid编辑行点击而不是编辑按钮点击
- 16. Angular UI Grid编辑
- 17. Kendo Grid内联编辑新行添加后消失
- 18. Kendo Grid - 自定义编辑器,更新不触发,行删除
- 19. ExtJS Grid中的行编辑
- 20. Kendo Grid - 使用下拉列表编辑器编辑线条(编辑自定义编辑器)
- 21. Telerik Kendo UI Grid MVC - 以编程方式取消编辑
- 22. Tab顺序在Cell编辑中不起作用Kendo UI Grid
- 23. Kendo UI Grid,可编辑模式不适用于本地数据
- 24. Kendo Grid用户界面编辑值但未保存
- 25. 如何在Kendo Angular Grid中禁用行选择切换?
- 26. Kendo Grid Kendo模板的可拖拽行
- 27. 通过内联编辑重新加载Kendo Grid后内联编辑
- 28. jqGrid,禁用编辑行
- 29. Kendo UI Grid获取行值
- 30. Kendo Grid - 行展开动画
看看这个解决方案 http://stackoverflow.com/questions/15893199/preventing-editing-a-row-in-kendo-grid – Filippo