原文 : http://blog.youkuaiyun.com/fwk1010/article/details/51970991
- jQuery(function($) {
- $('#dataTable').datagrid({
- //title:'菜单列表', //标题
- method : 'post',
- iconCls : 'icon-edit', //图标
- singleSelect : false, //多选
- width : 'auto',
- height : inHeight, //高度
- fitColumns : true, //自动调整各列,用了这个属性,下面各列的宽度值就只是一个比例。
- striped : true, //奇偶行颜色不同
- // collapsible:true,//可折叠
- url : "xxx.html", //数据来源
- sortName : 'id', //默认排序的列
- sortOrder : 'desc', //倒序
- remoteSort : true, //服务器端排序
- pageSize : 20,
- idField : 'id', //主键字段
- queryParams : {}, //查询条件
- pagination : true, //显示分页
- rownumbers : true, //显示行号
- columns : [ [ {
- field : 'ck',
- checkbox : true,
- width : 2
- }, //显示复选框
- {
- field : 'id', //若sortable为true则可以作为排序字段,请与数据库字段保持一致
- title : 'id',
- width : 20,
- sortable : true,
- formatter : function(value, row, index) {
- return row.id;
- }
- }, {
- field : 'start_time',
- title : '开始时间',
- width : 20,
- sortable : true,
- formatter : function(value, row, index) {
- return row.startTime;
- }
- }, {
- field : 'end_time',
- title : '结束',
- width : 20,
- sortable : true,
- formatter : function(value, row, index) {
- return row.endTime;
- }
- }
- ] ],
- toolbar : [ {
- text : '添加',
- iconCls : 'icon-add',
- handler : function() {
- addrow();
- }
- }, '-' ],
- onLoadSuccess : function(data) {
- $('#dataTable').datagrid('clearSelections'); //一定要加上这一句,要不然datagrid会记住之前的选择状态,删除时会出问题
- //遍历结果
- for ( var i = 0; i < data.rows.length; i++) {
- //根据status值使复选框 不可用
- if (data.rows[i].status == "1") {
- $("input[type='checkbox']")[i + 1].disabled = true;
- }
- }
- },
- onClickRow : function(rowIndex, rowData) {
- //根据status值 单击单选行不可用
- if (rowData.status == "1") {
- $('#dataTable').datagrid('unselectRow', rowIndex);
- } else {
- addrow();
- }
- },
- onDblClickRow : function(rowIndex, rowData) {
- //根据status值 双击单选行不可用
- if (rowData.status == "1") {
- $('#dataTable').datagrid('unselectRow', rowIndex);
- } else {
- addrow();
- }
- },
- onSelectAll : function(rows) {
- //根据status值 全选时某些行不选中
- $.each(rows, function(i, n) {
- if (n.status == "1") {
- $('#dataTable').datagrid('unselectRow', i);
- }
- });
- }
- });
- var p = $('#dataTable').datagrid('getPager');
- $(p).pagination({
- pageSize : 20,//每页显示的记录条数,默认为10
- pageList : [ 10, 15, 20, 25, 30, 50 ],//可以设置每页记录条数的列表
- beforePageText : '第',//页数文本框前显示的汉字
- afterPageText : '页 共 {pages} 页',
- displayMsg : '当前显示 {from} - {to} 条记录 共 {total} 条记录'
- });
- });