我正在使用 Devexpress MVC Grid,我添加了两个自定义按钮(编辑和复制),我正在执行操作。使用复制按钮,我正在使用现有数据创建新记录并在添加新行模式下打开网格。
以下是代码:
@Html.DevExpress().GridView(grid =>
{
grid.Name = "gvInformation";
grid.SettingsDetail.AllowOnlyOneMasterRowExpanded = true;
grid.SettingsEditing.Mode = GridViewEditingMode.EditForm;
//Callback Events
grid.CallbackRouteValues = new { Controller = "Case", Action = "InformationGridContent"};
grid.SettingsEditing.AddNewRowRouteValues = new { Controller = "Case", Action = "AddInformationRecord" };
grid.SettingsEditing.UpdateRowRouteValues = new { Controller = "Case", Action = "UpdateInformationRecord" };
grid.SettingsEditing.DeleteRowRouteValues = new { Controller = "Case", Action = "DeleteInformationRecord" };
grid.ClientSideEvents.BeginCallback = "BeginGridCallback";
grid.BeforeGetCallbackResult = (sender, e) =>
{
MVCxGridView gridView = sender as MVCxGridView;
if (isCopyRequired)
gridView.AddNewRow();
if (gridView.IsNewRowEditing)
{
gridView.SettingsText.CommandUpdate = Html.Raw("<span id='btnGridAdd'>Add</span>").ToHtmlString();
gridView.SettingsText.CommandCancel = Html.Raw("<span id='btnGridCancel'>Cancel</span>").ToHtmlString();
}
if (!gridView.IsNewRowEditing)
{
gridView.SettingsText.CommandUpdate = Html.Raw("<span id='btnGridUpdate'>Update</span>").ToHtmlString();
gridView.SettingsText.CommandCancel = Html.Raw("<span id='btnCancel'>Cancel</span>").ToHtmlString();
}
};
//Custom Copy Record Button
var btnCopy = new GridViewCommandColumnCustomButton { ID = "btnCopy" };
btnCopy.Text = "<i class=\"fa fa-copy fa-lg\" title='Copy'></i>";
grid.CommandColumn.CustomButtons.Add(btnCopy);
//Custom Edit Button
var btnEdit = new GridViewCommandColumnCustomButton { ID = "btnEdit" };
btnEdit.Text = "<i class=\"fa fa-pencil fa-lg\" title='Edit'></i>";
grid.CommandColumn.CustomButtons.Add(btnEdit);
//Custom Button Events
grid.ClientSideEvents.CustomButtonClick = "OnCustomButtonClick";
grid.CustomActionRouteValues = new { Controller = "Case", Action = "CustomInformationRecord" };
}
客户端事件:
var buttonCommand;
function OnCustomButtonClick(s, e) {
buttonCommand = e.buttonID;
s.PerformCallback();
}
function BeginGridCallback(s, e) {
//Grid Edit Button Click Event
if (buttonCommand === "btnEdit") {
e.customArgs["buttonCommand"] = "btnEdit";
}
//Grid Copy Button Click Event
if (buttonCommand === "btnCopy") {
e.customArgs["buttonCommand"] = "btnCopy";
}
}
它适用于复制按钮并在编辑表单模式下打开网格,但是当单击编辑按钮时,它不会在编辑模式下打开网格。有什么我想念的吗?