////////////////////////////
function editRow() {
var rows = grid.getSelecteds();
if (rows.length > 0) {
for (var i = 0, l = rows.length; i < l; i++) {
var row = rows;
grid.beginEditRow(row);
}
}
}
function addRow() {
var newRow = { name: "New Row" };
grid.addRow(newRow, 0);
grid.beginEditRow(newRow);
}
function removeRow() {
var rows = grid.getSelecteds();
if (rows.length > 0) {
grid.removeRows(rows, true);
}
}
function saveData() {
grid.commitEdit();
var data = grid.getChanges();
var json = mini.encode(data);
grid.loading("保存中,请稍后......");
$.ajax({
url: "testmodel.aspx?method=SaveEmployees",
data: { data: json },
type: "post",
success: function (text) {
grid.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
}
////////////////////////
//选择“部门”,设置“职位”
function onDepartChanged(e) {
var combo = e.sender;
var row = grid.getEditorOwnerRow(combo);
var editor = grid.getCellEditor("Position", row);
var id = combo.getValue();
var url = "../demo/data/AjaxService.aspx?method=GetPositionsByDepartmenId&id=" + id
editor.setUrl(url);
editor.setValue("");
}
//“职位”combo的url在cellbeginedit的时候,根据前面值自动设置
grid.on("cellbeginedit", function (e) {
if (e.field == "position") {
var editor = e.editor;
var id = e.record.dept_id;
var url = "../demo/data/AjaxService.aspx?method=GetPositionsByDepartmenId&id=" + id
editor.setUrl(url);
}
});