easyui datagrid属性和方法

本文可以当做api来使用

使用方法(Usage Example)

从现有的表单元素创建数据表格,定义在html中的行,列和数据。

<table class="easyui-datagrid">  
    <thead>  
        <tr>  
            <th data-options="field:'code'">Code</th>  
            <th data-options="field:'name'">Name</th>  
            <th data-options="field:'price'">Price</th>  
        </tr>  
    </thead>  
    <tbody>  
        <tr>  
            <td>001</td><td>name1</td><td>2323</td>  
        </tr>  
        <tr>  
            <td>002</td><td>name2</td><td>4612</td>  
        </tr>  
    </tbody>  
</table>  

通过<TABLE>标记创建的DataGrid。嵌套的<TH>标签定义的列的表。

<table class="easyui-datagrid" style="width:400px;height:250px"  
        data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true">  
    <thead>  
        <tr>  
            <th data-options="field:'code',width:100">Code</th>  
            <th data-options="field:'name',width:100">Name</th>  
            <th data-options="field:'price',width:100,align:'right'">Price</th>  
        </tr>  
    </thead>  
</table> 

使用JavaScript创建数据表格。

<table id="dg"></table>  
$('#dg').datagrid({   
    url:'datagrid_data.json',   
    columns:[[   
        {field:'code',title:'Code',width:100},   
        {field:'name',title:'Name',width:100},   
        {field:'price',title:'Price',width:100,align:'right'}   
    ]]   
});  

查询数据填充数据表格。

$('#dg').datagrid('load', {   
    name: 'easyui',   
    address: 'ho'  
});

数据更改与服务器交互,刷新当前数据。

$('#dg').datagrid('reload');    // reload the current page data  
数据表格属性(DataGrid Properties)

属性继承控制面板,以下是数据表格独有的属性。

名称类型描述默认值
columnsarray数据表格列配置对象,查看列属性以获取更多细节。undefined
frozenColumnsarray跟列属性一样,但是这些列固定在左边,不会滚动。undefined
fitColumnsboolean设置为true将自动使列适应表格宽度以防止出现水平滚动。false
autoRowHeightboolean定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。true
toolbararray,selector数据表格顶部面板的工具栏。可能的值:
1)数组,每个工具选项和链接按钮相同。
2)选择显示的工具栏。
在一个<div>的标签定义工具栏:
$('#dg').datagrid({
	toolbar: '#tb'
});
<div id="tb">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"/a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true"/a>
</div>

通过数组定义工具栏:

$('#dg').datagrid({
	toolbar: [{
		iconCls: 'icon-edit',
		handler: function(){alert('edit')}
	},'-',{
		iconCls: 'icon-help',
		handler: function(){alert('help')}
	}]
});
null
stripedboolean设置为true将交替显示行背景。false
methodstring请求远程数据的方法类型。post
nowrapboolean设置为true,当数据长度超出列宽时将会自动截取。true
idFieldstring表明该列是一个唯一列。null
urlstring一个用以从远程站点请求数据的超链接地址。null
loadMsgstring当从远程站点载入数据时,显示的一条快捷信息。Processing, please wait …
paginationboolean设置true将在数据表格底部显示分页工具栏。false
rownumbersboolean设置为true将显示行数。false
singleSelectboolean设置为true将只允许选择一行。false
checkOnSelectboolean如果为true,该复选框被选中/取消选中,当用户点击某一行上。如果为false,该复选框仅检查/取消选中,当用户点击完全的复选框。
此属性是1.3版本。
true
selectOnCheckboolean如果设置为true,单击一个复选框,将始终选择行。如果为false,不会选择行选中该复选框。
此属性是1.3版本。
true
pagePositionstring 定义的分页栏的位置。可用的值有 'top','bottom','both'。
此属性是可自1.3版本。
bottom
pageNumbernumber当设置分页属性时,初始化分页码。1
pageSizenumber当设置分页属性时,初始化每页记录数。10
pageListarray当设置分页属性时,初始化每页记录数列表。[10,20,30,40,50]
queryParamsobject当请求远程数据时,发送的额外参数。

示例:

$('#dg').datagrid({
	queryParams: {
		name: 'easyui',
		subject: 'datagrid'
	}
});
{}
sortNamestring当数据表格初始化时以哪一列来排序。null
sortOrderstring定义排序顺序,可以是'asc'或者'desc'(正序或者倒序)。asc
remoteSortboolean定义是否通过远程服务器对数据排序。true
showFooterboolean定义是否显示行底(如果是做统计表格,这里可以显示总计等)。false
rowStylerfunction返回样式,如:'background:red',function有2个参数:
index:行索引,从0开始.
row:对应于该行记录的对象。

示例:

$('#dg').datagrid({
	rowStyler: function(index,row){
		if (row.listprice>80){
			return 'background-color:#6293BB;color:#fff;';
		}
	}
});
 
loaderfunction定义如何从远程服务器加载数据。返回false可以取消该操作。这个函数接受以下参数:
param: 参数对象传递到远程服务器。
success(data): 回调函数将被调用成功检索的数据。
error():回调函数将被调用失败时检索数据。
json loader
loadFilterfunction返回过滤的数据显示。该函数需要一个参数'data',表示原始数据。您可以更改源数据的标准数据格式。此函数必须返回标准数据对象中包含的“total”和“rows”的属性。

示例:

// removing 'd' object from asp.net web service json output
$('#dg').datagrid({
	loadFilter: function(data){
		if (data.d){
			return data.d;
		} else {
			return data;
		}
	}
});
 
editorsobject定义当编辑一行时的编辑模式。predefined editors
viewobject定义数据表格的视图。default view
列属性(Column Properties)

数据表格的列是一个对象数组,即这个对象中的元素也是一个数组(js中数组是对象)。 对象数组中的每一个元素都是可配置的对象,每个可配置对象定义一个列。

示例:

columns:[[   
    {field:'itemid',title:'Item ID',rowspan:2,width:80,sortable:true},   
    {field:'productid',title:'Product ID',rowspan:2,width:80,sortable:true},   
    {title:'Item Details',colspan:4}   
],[   
    {field:'listprice',title:'List Price',width:80,align:'right',sortable:true},   
    {field:'unitcost',title:'Unit Cost',width:80,align:'right',sortable:true},   
    {field:'attr1',title:'Attribute',width:100},   
    {field:'status',title:'Status',width:60}   
]] 

 

名称类型描述默认值
titlestring列标题。undefined
fieldstring列字段。undefined
widthnumber列宽。undefined
rowspannumber表明一个单元格跨几行。undefined
colspannumber表明一个单元格跨几列。undefined
alignstring表明如何对其列数据,可选值:'left','right','center'。undefined
sortableboolean设置为true允许对该列排序。undefined
resizableboolean设置为true允许该列被缩放。undefined
hiddenboolean设置为true将隐藏列。undefined
checkboxboolean设置为true将显示复选框。undefined
formatterfunction格式化单元格函数,有3个参数:
value:字段的值。
rowData:行数据。
rowIndex:行索引。

示例:

$('#dg').datagrid({
	columns:[[
		{field:'userId',title:'User', width:80,
			formatter: function(value,row,index){
				if (row.user){
					return row.user.name;
				} else {
					return value;
				}
			}
		}
	]]
});
undefined
stylerfunction单元格样式函数,返回样式字符串装饰表格如'background:red',function有3个参数:
value:字段值。
rowData:行数据。
rowIndex:行索引。

示例:

$('#dg').datagrid({
	columns:[[
		{field:'listprice',title:'List Price', width:80, align:'right',
			styler: function(value,row,index){
				if (value < 20){
					return 'background-color:#ffee00;color:red;';
				}
			}
		}
	]]
});
undefined
sorterfunctionT自定义字段排序函数,有2个参数:
a:该列的第一个值。
b:该列的第二个值。

示例:

$('#dg').datagrid({
	remoteSort: false,
	columns: [[
		{field:'date',title:'Date',width:80,sortable:true,align:'center',  
			sorter:function(a,b){  
				a = a.split('/');  
				b = b.split('/');  
				if (a[2] == b[2]){  
					if (a[0] == b[0]){  
						return (a[1]>b[1]?1:-1);  
					} else {  
						return (a[0]>b[0]?1:-1);  
					}  
				} else {  
					return (a[2]>b[2]?1:-1);  
				}  
			}  
		}
	]]
});
undefined
editorstring,object表明编辑类型。如果属性是字符串类型表示编辑类型,如果是对象则包含2个参数:
type:字符串,编辑类型,可选值:text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree。
options:对象,对象于编辑类型的编辑器属性。
undefined

   转载: https://www.cnblogs.com/prefect/p/5664513.html

   详细文档:http://www.jeasyui.net/plugins/183.html

转载于:https://www.cnblogs.com/guofz/p/8846559.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值