使用Jquery网格的ASP.NETMVC
我可以查看哪个简化版的real screen有几个下拉控件,允许用户选择类别,然后选择子类别-输入金额,然后单击“添加”按钮。然后,Add按钮将新行添加到JQuery网格中 然后,控件重置,允许用户选择其他类别、子类别和金额,然后再次单击“添加”,将数据添加到网格中使用Jquery网格的ASP.NETMVC,jquery,asp.net-mvc,jquery-plugins,Jquery,Asp.net Mvc,Jquery Plugins,我可以查看哪个简化版的real screen有几个下拉控件,允许用户选择类别,然后选择子类别-输入金额,然后单击“添加”按钮。然后,Add按钮将新行添加到JQuery网格中 然后,控件重置,允许用户选择其他类别、子类别和金额,然后再次单击“添加”,将数据添加到网格中 $(function () { $('#addSplit').click(function () { var mydata = [
$(function () {
$('#addSplit').click(function () {
var mydata = [
{ category: $('#SelectedCategoryId option:selected').text(), subcategory: $('#SelectedSubCategoryId option:selected').text(), costcenter: $('#SelectedCostCenterId option:selected').text(), budget: $('#SelectedBudgetId option:selected').text(), amount: $('#amount').val() }
];
for (var i = 0; i <= mydata.length; i++)
jQuery("#list4").jqGrid('addRowData', i + 1, mydata[i]);
});
});
行添加得很好。我需要以某种方式添加隐藏列来存储ID
然后,用户将单击“保存”。我想以某种方式在网格中进行编辑,获取要添加的ID,然后以某种方式将其与模型一起返回给我的MVC控制器进行存储
这能做到吗?还是有更好的办法来解释我的想法?你必须定义你的模型。 我将定义一个函数,它接收一个数据数组,并将其绑定到数据:DataToLoad
function LoadGrid(DataToLoad) {
jQuery("#list4").jqGrid({
data: DataToLoad,
datatype: "local",
width: 790,
height: 250,
rowNum: 999999,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', hidden:true, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number"},
{name:'tax',index:'tax', width:80, editable: true, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
emptyrecords: "No records to view",
cellEdit: true,
cellsubmit: 'clientArray',
viewrecords: true,
shrinkToFit: false,
scroll: false,
rownumbers: true,
hidegrid: false,
pager: "#plist47",
caption: "Manipulating Array Data"
});
}
如您所见,第一列是隐藏的:true
然后可以在加载数组的情况下调用函数,而不是将行添加到网格中:
$("#addSplit").bind('click', function(){
jQuery("#list4").GridUnload();
// LOAD the ARRAY here.
LoadGrid(mydata);
});
记住卸载网格jQuerylist4.GridUnload 谢谢@vandalo-当我单击“保存”按钮(将模型提交回控制器的“提交”按钮)时,数组是否可用?是的,您可以在页面脚本中将数组声明为全局数组,以便您可以从页面上的其他函数javascript读取其内容。如果你想提交数组,最好的办法可能是使用这个工具,截取beforeSubmit事件并将你的数组放在某个地方以便发布。