【发布时间】:2012-08-24 19:34:36
【问题描述】:
我正在使用子网格。我将单击子网格中的“添加会话”链接,它将向子网格添加行。我可以添加 n 行。现在我需要验证子网格中每个添加的行。我怎么能这样做?
我在下面粘贴我的代码...
//This is my jqgrid code:
function loadSubGrid(subgrid_id, row_id) {
DayID = $('#DayEvents').getCell(row_id, 'DayID');
var pager_id;
subgrid_table_id = subgrid_id + "_t";
pager_id = "p_" + subgrid_table_id;
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><a href=# id='AddSession' OnClick='addRow(\"" + subgrid_table_id + "\");'>add session</a><div id='" + pager_id + "' class='scroll'></div>");
jQuery("#" + subgrid_table_id).jqGrid({
url: 'Event.asmx/GetSubGridDay',
datatype: 'json',
mtype: 'POST',
cellEdit: false,
cellsubmit: 'clientarray',
onCellSelect: GridCellClick,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: PrepareGridPostData,
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['sessionId', 'session', 'start time', 'end time', 'Speaker'],
colModel:
[{ name: 'SessionId', index: 'SessionId', width: 90, formatter: 'text', align: 'center', hidden: true },
{ name: 'SessionName', index: 'SessionName', width: 90, formatter: 'text', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} },
{ name: 'StartTime', index: 'StartTime', width: 90, formatter: 'text', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataInit: function(element) {
$(element).timepicker({})
}, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]}
},
{ name: 'EndTime', index: 'EndTime', width: 90, formatter: 'text', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataInit: function(element) {
$(element).timepicker({})
}, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]}
},
{ name: 'Speaker', index: 'Speaker', width: 300, editable: false, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Speaker('", addParam: "');"} },
],
rowNum: 10,
height: 'auto',
autowidth: true
});
}
现在在上面代码的这一行中,它调用了一个函数来打开一个对话框..
{ name: 'Speaker', index: 'Speaker', width: 300, editable: false, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Speaker('", addParam: "');"} },
打开对话框的功能如下:
function Speaker() {
$("#SpeakerPopUp").dialog('open');
$("#SpeakerPopUp").dialog(
{
autoOpen: true,
height: 500,
width: 500,
modal: true,
title: 'Speakers List',
open: gridData,
buttons: {
'cancel': function CancelCheck() { $(this).dialog('close'); },
'Save': SpeakerSelectionSave
}
});
}
}
现在我需要的是,如果该子网格行中的任何一列为空,它不应该打开对话框。请帮帮我。希望我能清楚地解释我的需求。
【问题讨论】:
-
@tpeczek 请帮我解决这个问题..
-
澄清一下,所有的行都来自服务器,但你不确定数据库中是否所有的列都被填满了对吧?
-
@tpeczek 我在子网格中动态添加行。所以最初它是空的。
-
最好的方法似乎是自定义格式化程序,但我会看看你的方法是否可以实现。
-
@Nick Craver 请帮帮我..
标签: jquery jqgrid jquery-validate dialog subgrid