我有几个关于 EJ2 电子表格控件的问题。
- 即使 allowSave 等于 true,“另存为”也被禁用。
- 电子表格来自模型列表。用户可以编辑某些字段。单击按钮时,如何将电子表格数据返回到控制器以保存到数据库。
- 有没有办法使某些行不可编辑。谢谢
这是视图中的代码。
<form asp-action="Calculate" id="frmBallotQty">
@Html.Hidden("hidBallotPercent")
@Html.Hidden("hidAbsenteePercent")
@Html.Hidden("hidRound25")
</form>
<form asp-action="ClearAll" id="frmClearAll"></form>
<form asp-action="ClearAbsentee" id="frmClearAbsentee"></form>
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#userAction").val("initialLoad");
loadSpreadsheet();
});
//*****************************************
//** Load Spreadsheet
//*****************************************
function loadSpreadsheet() {
@*alert("@Model.userAction");*@
@{
var sheetData = "[{ " +
"rows: [{ " +
"index: 0, " +
"cells: [ " +
"{ index: 0, value: 'Id', style: { fontWeight: 'bold' } }, " +
"{ value: 'Vote Center Name', style: { fontWeight: 'bold' } }, " +
"{ value: 'Precinct', style: { fontWeight: 'bold' } }, " +
"{ value: 'Ballot Style', style: { fontWeight: 'bold' } }, " +
"{ value: 'Ballot Quantity', style: { fontWeight: 'bold' } }, " +
"{ value: 'Absentee Quantity', style: { fontWeight: 'bold' } }, " +
"{ value: 'Registered Voters', style: { fontWeight: 'bold' } } " +
"] " +
"}, ";
foreach (var ballotQty in Model)
{
sheetData = sheetData + "{ cells: [ ";
sheetData = sheetData + "{ value: '" + ballotQty.Id + "' }, ";
sheetData = sheetData + "{ value: '" + ballotQty.VoteCenterName + "' }, ";
sheetData = sheetData + "{ value: '" + ballotQty.PrecinctName + "' }, ";
sheetData = sheetData + "{ value: '" + ballotQty.BallotStyle + "', style: { textAlign: 'right' } }, ";
sheetData = sheetData + "{ value: '" + ballotQty.BallotQty + "' }, ";
sheetData = sheetData + "{ value: '" + ballotQty.AbsenteeQty + "' }, ";
sheetData = sheetData + "{ value: '" + ballotQty.RegisteredVoters + "' } ";
sheetData = sheetData + " ] }, ";
}
sheetData = sheetData + " ], columns: [" +
"{ width: 80 }, { width: 80 }, { width: 82 },{ width: 160 }, { width: 110 }, { width: 130 }, { width: 130 }" +
"] " +
"}] ";
}
// Initialize the Spreadsheet component.
var sheet = @Html.Raw(sheetData);
// Initialize the Spreadsheet component.
var spreadsheet = new ej.spreadsheet.Spreadsheet({
allowOpen: false,
allowSave: true,
sheets: sheet,
});
// Render initialized Spreadsheet.
spreadsheet.appendTo('#spreadsheet');
}
//*****************************************
//** Calculate
//*****************************************
$("#btnCalculate").click(function (e) {
var validationMsg = "";
//Validate
if ($("#BallotsPercent").val().trim() == "") {
validationMsg = "Ballots Percent Must Be Entered For Calculate. \n"
}
else {
if (isNaN($("#BallotsPercent").val())) {
validationMsg = "Ballots Percent Must Be Numeric. \n"
}
}
if ($("#AbsenteePercent").val().trim() == "") {
validationMsg = validationMsg + "Absentee Percent Must Be Entered For Calculate. \n"
}
else {
if (isNaN($("#AbsenteePercent").val())) {
validationMsg = validationMsg + "Absentee Percent Must Be Numeric. "
}
}
if (validationMsg != "") {
magalert.errorMessage(validationMsg)
return false;
}
$("#hidBallotPercent").val($("#BallotsPercent").val());
$("#hidAbsenteePercent").val($("#AbsenteePercent").val());
$("#hidRound25").val($("input[name='round']:checked").val());
$('form#frmBallotQty').submit();
});
//*****************************************
//** Update
//*****************************************
$("#btnUpdate").click(function (e) {
alert("update");
});
//*****************************************
//** Clear All
//*****************************************
$("#btnClearAll").click(function (e) {
$('form#frmClearAll').submit();
});
//*****************************************
//** Clear Absentee
//*****************************************
$("#btnClearAbsentee").click(function (e) {
$('form#frmClearAbsentee').submit();
});
</script>
}