ASPxGridView - 如何在编辑行时使某些字段编辑器为只读并在添加新行时允许它们进行编辑
ASPxGridView - How to make some field editors read-only when editing a row and allow their editing when adding a new row
我在这里遵循它,https://www.devexpress.com/Support/Center/Example/Details/E5116 并在 ASP.NET MVC 中应用了给定的示例。以下是我的gridview设置示例部分代码:
settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Row;
settings.CellEditorInitialize = (s, e) =>
{
ASPxGridView grid = s as ASPxGridView;
ASPxEdit editor = (ASPxEdit)e.Editor;
if (e.Column.FieldName == "columnName1" || e.Column.FieldName == "columnName2")
{
e.Editor.ReadOnly = !grid.IsNewRowEditing;
}
};
现在我无法在更新现有行数据的同时编辑两个单元格,这看起来很完美。
但我无法在使用新按钮创建新行时编辑两列。
注意:- 它在以下时间工作:
settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
但在编辑模式为 批处理 时不起作用。
最终我在 DevExpress 支持的帮助下实现了这一点:
局部视图中的网格设置如下:
@Html.DevExpress().GridView(settings=> {
settings.Name = "gridViewPartial";
settings.CallbackRouteValues = new { Controller = "Home", Action = "gridViewPartial" };
settings.SettingsEditing.BatchUpdateRouteValues = new { Controller = "Admin", Action = "gridViewBatchUpdate" };
settings.KeyFieldName = "Id";
settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Cell;
//to handle edit events on client side
**settings.ClientSideEvents.BatchEditStartEditing = "OnBatchStartEdit";**
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowNewButtonInHeader = true;
settings.Columns.Add(column =>
{
column.FieldName = "Id";
column.Caption = "ID";
column.ColumnType = MVCxGridViewColumnType.SpinEdit;
});
settings.Columns.Add(column =>
{
column.FieldName = "Name";
column.Caption = "Name";
});
}).Bind(Model).GetHtml()
我在其中引用部分视图的网格普通页面:
//script to handle edit event
function OnBatchStartEdit(s, e) {
if ((e.focusedColumn.fieldName == "Id") && (e.visibleIndex > -1)) //cancel example
e.cancel = true;;
}
进一步参考
访问这里 https://www.devexpress.com/Support/Center/Question/Details/T386483
我在这里遵循它,https://www.devexpress.com/Support/Center/Example/Details/E5116 并在 ASP.NET MVC 中应用了给定的示例。以下是我的gridview设置示例部分代码:
settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Row;
settings.CellEditorInitialize = (s, e) =>
{
ASPxGridView grid = s as ASPxGridView;
ASPxEdit editor = (ASPxEdit)e.Editor;
if (e.Column.FieldName == "columnName1" || e.Column.FieldName == "columnName2")
{
e.Editor.ReadOnly = !grid.IsNewRowEditing;
}
};
现在我无法在更新现有行数据的同时编辑两个单元格,这看起来很完美。
但我无法在使用新按钮创建新行时编辑两列。
注意:- 它在以下时间工作:
settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
但在编辑模式为 批处理 时不起作用。
最终我在 DevExpress 支持的帮助下实现了这一点:
局部视图中的网格设置如下:
@Html.DevExpress().GridView(settings=> {
settings.Name = "gridViewPartial";
settings.CallbackRouteValues = new { Controller = "Home", Action = "gridViewPartial" };
settings.SettingsEditing.BatchUpdateRouteValues = new { Controller = "Admin", Action = "gridViewBatchUpdate" };
settings.KeyFieldName = "Id";
settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Cell;
//to handle edit events on client side
**settings.ClientSideEvents.BatchEditStartEditing = "OnBatchStartEdit";**
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowNewButtonInHeader = true;
settings.Columns.Add(column =>
{
column.FieldName = "Id";
column.Caption = "ID";
column.ColumnType = MVCxGridViewColumnType.SpinEdit;
});
settings.Columns.Add(column =>
{
column.FieldName = "Name";
column.Caption = "Name";
});
}).Bind(Model).GetHtml()
我在其中引用部分视图的网格普通页面:
//script to handle edit event
function OnBatchStartEdit(s, e) {
if ((e.focusedColumn.fieldName == "Id") && (e.visibleIndex > -1)) //cancel example
e.cancel = true;;
}
进一步参考 访问这里 https://www.devexpress.com/Support/Center/Question/Details/T386483