editor: { type: 'spinner' }将会使用$.ligerDefaults.Grid.editors['spinner'] 进行创建编辑器进行构建。
{ display: '<a href="javascript:void(0)">部门</a>', //表头列显示的文本,支持html name: 'name', align: 'left' },或者使用headerRender:
//表头内容自定义函数 headerRender: function (column)
{ return "<b>" + column.display + "</b>"; },
$("#maingrid4").ligerGrid({ checkbox: true, columns: [ { display: '主键', name: 'CustomerID', align: 'left', width: 120 }, { display: '公司名', name: 'CompanyName', minWidth: 60 }, { display: '联系名', name: 'ContactName', width: 50,align:'left' }, { display: '联系名', name: 'ContactName', minWidth: 140 }, { display: '联系名', name: 'ContactName', minWidth: 140 }, { display: '联系名', name: 'ContactName', minWidth: 140 }, { display: '联系名', name: 'ContactName', minWidth: 140 }, { display: '城市', name: 'City' } ], dataAction: 'server',pageSize:30, url: "../../service/NwindDataHandler.ashx?View=Customers", sortName: 'CustomerID', width: '100%',height:'100%' });
var grid;
$(function ()
{
grid = $("#maingrid4").ligerGrid({
checkbox: true,
columns: [
{ display: '主键', name: 'CustomerID', align: 'left', width: 120 },
{ display: '公司名', name: 'CompanyName', minWidth: 60 },
{ display: '联系名', name: 'ContactName', width: 50, align: 'left' },
{ display: '城市', name: 'City' }
], dataAction: 'server', pageSize: 30,
url: "../../service/NwindDataHandler.ashx?View=Customers", sortName: 'CustomerID',
width: '100%', height: '100%',
onCheckRow: function (checked,data,rowindex,rowobj)
{
checked && $.ligerDialog.alert('选择的是'+data.CustomerID);
}
});
$("#pageloading").hide();
});
function getCheckedData() // 获取选择的复选框记录
{
var rows = grid.getCheckedRows();
var str = "";
$(rows).each(function ()
{
str += this.CustomerID + ",";
});
$.ligerDialog.alert('选择的是' + str);
}
var jsonObj = {}; jsonObj.Rows = [ { id: 3, name: "林三", sex: "男", birthday: "1989-01-12" }, { id: 43, name: "陈丽", sex: "女", birthday: "1989-01-12" }, { id: 33, name: "啊三", sex: "男", birthday: "1981-12-12" }, { id: 34, name: "表三", sex: "男", birthday: "1983-01-12" }, { id: 43, name: "陈丽", sex: "女", birthday: "1989-01-12" }, { id: 33, name: "成三", sex: "男", birthday: "1989-11-23" }, { id: 34, name: "都三", sex: "女", birthday: "1989-04-12" }, { id: 324, name: "鄂三", sex: "男", birthday: "1999-05-15" }, { id: 344, name: "林三", sex: "男", birthday: "1969-02-21" }, { id: 1, name: "王开", sex: "男", birthday: "1989-01-12" } ]; $("#maingrid").ligerGrid({ columns: [ { display: '', width: 30, isAllowHide: false, name: 'checkbox', isSort: false, render: function (row) { var html = '<input type="checkbox" rowid="' + row.id + '">'; return html; }, headerRender: function (column) { var html = '<input type="checkbox" onclick="selectAll(this)">'; return html; } }, { display: '主键', name: 'id', width: 50, type: 'int' }, { display: '名字', name: 'name', width: 50 }, { display: '性别', name: 'sex', width: 50, isSort: false }, { display: '生日', name: 'birthday', type: 'date', width: 100 }, { display: '模板列', isAllowHide: false, render: function (row) { var html = '<a href="#" onclick="onedit(' + row.id + ')">编辑</a>'; return html; } } ],width:'100%', data: jsonObj, url: "../Default.aspx", pkName: 'id', pageSizeOptions: [5, 10, 15, 20], onAfterShowData: function (grid) { if ($.fn.ligerCheckBox) $(".l-grid-body input:checkbox,.l-grid-hd-cell input:checkbox", grid).ligerCheckBox({ css: { marginTop: 3} }) } });
事件名 | 参数 | 描述 |
onAfterAddRow | (e) | 增加行后事件 |
onAfterBeginEdit | (e) | 开始编辑后事件 |
onAfterChangeColumnWidth | (column, newwidth) | 改变列宽度事件 |
onAfterShowData | (data) | 显示完数据事件 |
onAfterSubmitEdit | (e) | 提交编辑 事件 |
onBeforeChangeColumnWidth | (column, newwidth) | 验证 改变列宽度 是否通过 |
onBeforeCheckAllRow | (checked, grid element) | 选择前事件,可以通过return false阻止操作(复选框 全选/全不选) |
onBeforeEdit | (e) | 编辑前事件 |
onBeforeShowData | (data) | 显示数据前事件,可以通过reutrn false阻止操作 |
onBeforeSubmitEdit | (e) | 验证编辑器结果是否通过 |
onBeginEdit | (e) | 验证 开始编辑 是否通过 |
onCancelEdit | (e) | 取消编辑 事件 |
onChangeSort | () | 改变排序事件 |
onCheckAllRow | (checked, grid element) | 选择事件(复选框 全选/全不选) |
onCheckRow | (checked, rowdata, rowindex, rowDomElement) | 选择事件(复选框) |
onContextmenu | (parm, e) | 右击事件 |
onDblClickRow | (rowdata, rowindex, rowDomElement) | 双击行事件 |
onDragCol | (node) | 拖动列事件 |
onError | () | 错误事件 |
onLoaded | () | 加载完函数 |
onLoading | () | 加载时函数 |
onReload | () | 刷新事件,可以通过return false来阻止操作 |
onSelectRow | (rowdata, rowindex, rowDomElement) | 选择行事件 |
onSubmit | () | 提交前事件 |
onSuccess | () | 成功事件 |
onToFirst | () | 第一页,可以通过return false来阻止操作 |
onToggleCol | () | 切换列事件 |
onToLast | () | 最后一页,可以通过return false来阻止操作 |
onToNext | () | 下一页,可以通过return false来阻止操作 |
onToPrev | () | 上一页,可以通过return false来阻止操作 |
onUnSelectRow | (rowdata, rowindex, rowDomElement) | 取消选择行事件 |
例子
var grid = $("#maingrid").ligerGrid({ columns:
[ { name: 'id', display: '序号', width: 200 }, { name: 'name', display: '名称', width: 300 } ], data: { Rows: griddata }, onSelectRow: function (rowdata, rowindex) { //行记录 对于数据行 //行索引 第几行,从0开始 alert(rowdata.name); } }); grid.bind('SelectRow', function (rowdata, rowindex) { //this 这里的this都是指向grid //行记录 对于数据行 //行索引 第几行,从0开始 alert(rowdata.name); });
方法 | 参数 | 描述 |
addEditRow | (rowdata) |
|
addRow | (rowdata, rowParm, isBefore, parentRow) |
|
addRows | (rowdataArr) |
|
appendRow | (rowData, targetRow, nearRow, isBefore) |
|
beginEdit | (rowParm) |
|
cancelEdit | (rowParm) |
|
changeHeaderText | (columnparm, headerText) |
|
changePage | (ctype) |
|
changeSort | (columnName, sortOrder) |
|
collapse | (targetRow) |
|
collapseDetail | (rowParm) |
|
deleteRow | (rowParm) |
|
deleteSelectedRow | () |
|
demotion | (targetRow) |
|
endEdit | (rowParm) |
|
expand | (targetRow) |
|
extendDetail | (rowParm) |
|
formatRecord | (record) |
|
getAdded | () |
|
getCheckedRowObjs | () |
|
getCheckedRows | () |
|
getChidren | (rowParm) |
|
getColumn | (columnpam) |
|
getColumns | (columnLevel) |
|
getColumnType | (columnname) |
|
getData | (status, removeStatus) |
|
getDeleted | () |
|
getParent | (rowParm) |
|
getRowObj | (rowParm) |
|
getSelected | () |
|
getSelectedRow | () |
|
getSelectedRowObj | () |
|
getSelectedRowObjs | () |
|
getSelectedRows | () |
|
getSelecteds | () |
|
getUpdated | () |
|
hasChildren | (rowParm) |
|
isLeaf | (rowParm) |
|
isTotalSummary | () |
|
loadData | (loadDataParm) |
|
loadServerData | (param, clause) |
|
reRender | (e) |
|
setColumnWidth | (columnparm, value) |
|
setOptions | (parms) |
|
SubmitEdit | (rowParm) |
|
toggle | (targetRow) |
|
toggleCol | (columnparm, visible) |
|
updateCell | (cell, value, rowParm) |
|
updateRow | (newRowData, rowDom) |
|
upgrade | (targetRow) |
|
<a class="l-button" href="javascript:selectRow(2)">选择行(3)</a> <a class="l-button" href="javascript:getSelectRow()">获取选择</a>
var grid = $("#maingrid").ligerGrid({ columns: [ { name: 'id', display: '序号', width: 200 }, { name: 'name', display: '名称', width: 300 } ] }); grid.set({ data: { Rows: griddata} }); function selectRow(index) { grid.select(index); } function getSelectRow() { var rows = grid.getSelecteds(); for (var i in rows) { alert(rows[i].name); } }