其中checkType 变量是从界面的文本框中域中读取的webgrid的显示方式。其实这两种方式只不过其中一种是用复选框来读取cell中的值,另一种是用表格自带的多选方式来进行选择。
function getSelectedValue(col) { //col列的key值
var grid = igtbl_getGridById('_dataListGrid'); //dataListGrid表名
var selRowLen = igtbl_getLength(grid.SelectedRows);
var checkType = document.getElementById('_checkType').value;
var allKeys = "";
if (checkType == "webgrid") {
var i = 0;
for (var rowId in grid.SelectedRows) {
var row = igtbl_getRowById(rowId);
var colCell = row.getCellFromKey(col);
if (i == selRowLen - 1) {
allKeys = allKeys + colCell.getValue();
i++;
}
}
return allKeys;
}
else if (checkType == "checkbox") {
var rowLen = grid.RowsServerLength;
for (var i = 0, j = 0; i < rowLen; i++) {
var rowId = 'xdataListGrid_r_' + i;
var row = igtbl_getRowById(rowId);
var cell = row.getCellFromKey('sel');
var colCell = row.getCellFromKey(col);
if (cell.getValue() == "true") { //判断是否是第一个被勾选的单元格
if (j < 2) {
++j;
}
if (j == 1) {
allKeys = allKeys + colCell.getValue();
}
else {
allKeys = allKeys + "," + colCell.getValue();
}
}
}
return allKeys;
}
}