JQuery Easy Ui DataGrid
Extend from $.fn.panel.defaults. Override defaults with $.fn.datagrid.defaults.
The datagrid displays data in a tabular format and offers rich support to select, sort, group and edit data. The datagrid has been designed to reduce development time and to require no specific knowledge from developers. It is both featherweight and feature-rich. Cell merging, multi-column headers, frozen columns and footers are just a few of its features.
依赖
- panel
- resizable
- linkbutton
- pagination
用法示例
Create datagrid from an existing table element, defining columns, rows, and data in 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
Create datagrid via <table> markup. The nested <th> tags define the columns on the table.
- <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
Create datagrid using javascript is also allowed.
- <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'}
- ]]
- });
Query data with some parameters.
- $('#dg').datagrid('load', {
- name: 'easyui',
- address: 'ho'
- });
After changing data to server, refresh the front data.
- $('#dg').datagrid('reload'); // reload the current page data
表格属性
The properties extend from panel. below is the added properties for datagrid.
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| columns | array | The datagrid columns config object, see column properties for more details. | undefined |
| frozenColumns | array | Same as the columns property, but the these columns will be frozen on left. | undefined |
| fitColumns | boolean | True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling. | false |
| resizeHandle | string | Resizing column position, Available value are: 'left','right','both'. When 'right', users can resize columns by dragging the right edge of column headers, etc. This property is available since version 1.3.2. |
right |
| autoRowHeight | boolean | Defines if set the row height based on the contents of that row. Set to false can improve loading performance. | true |
| toolbar | array,selector | The top toolbar of datagrid panel. Possible values: 1) an array, each tool options are same as linkbutton. 2) a selector that indicate the toolbar. Define toolbar within a <div> tag: $('#dg').datagrid({
Define toolbar via array: $('#dg').datagrid({
|
null |
| striped | boolean | True to stripe the rows. | false |
| method | string | The method type to request remote data. | post |
| nowrap | boolean | True to display data in one line. Set to true can improve loading performance. | true |
| idField | string | Indicate which field is an identity field. | null |
| url | string | A URL to request data from remote site. | null |
| data | array,object | The data to be loaded. This property is available since version 1.3.2.
Code example: $('#dg').datagrid({
|
null |
| loadMsg | string | When loading data from remote site, show a prompt message. | Processing, please wait … |
| pagination | boolean | True to show a pagination toolbar on datagrid bottom. | false |
| rownumbers | boolean | True to show a row number column. | false |
| singleSelect | boolean | True to allow selecting only one row. | false |
| checkOnSelect | boolean | If true, the checkbox is checked/unchecked when the user clicks on a row. If false, the checkbox is only checked/unchecked when the user clicks exactly on the checkbox. This property is available since version 1.3. |
true |
| selectOnCheck | boolean | If set to true, clicking a checkbox will always select the row. If false, selecting a row will not check the checkbox. This property is available since version 1.3. |
true |
| pagePosition | string | Defines position of the pager bar. Available values are: 'top','bottom','both'. This property is available since version 1.3. |
bottom |
| pageNumber | number | When set pagination property, initialize the page number. | 1 |
| pageSize | number | When set pagination property, initialize the page size. | 10 |
| pageList | array | When set pagination property, initialize the page size selecting list. | [10,20,30,40,50] |
| queryParams | object | When request remote data, sending additional parameters also.
Code example: $('#dg').datagrid({
|
{} |
| sortName | string | Defines which column can be sorted. | null |
| sortOrder | string | Defines the column sort order, can only be 'asc' or 'desc'. | asc |
| multiSort | boolean | Defines if to enable multiple column sorting. This property is available since version 1.3.4. | false |
| remoteSort | boolean | Defines if to sort data from server. | true |
| showHeader | boolean | Defines if to show row header. | true |
| showFooter | boolean | Defines if to show row footer. | false |
| scrollbarSize | number | The scrollbar width(when scrollbar is vertical) or height(when scrollbar is horizontal). | 18 |
| rowStyler | function | Return style such as 'background:red'. The function take two parameter: rowIndex: the row index, start with 0 rowData: the record corresponding to this row Code example: $('#dg').datagrid({
|
|
| loader | function | Defines how to load data from remote server. Return false can abort this action. This function takes following parameters: param: the parameter object to pass to remote server. success(data): the callback function that will be called when retrieve data successfully. error(): the callback function that will be called when failed to retrieve data. |
json loader |
| loadFilter | function | Return the filtered data to display. The function take one parameter 'data' that indicate the original data. You can change original source data to standard data format. This function must return standard data object that contain 'total' and 'rows' properties.
Code example: // removing 'd' object from asp.net web service json output |
|
| editors | object | Defines the editor when editing a row. | predefined editors |
| view | object | Defines the view of datagrid. | default view |
列属性
The DataGrid Columns is an array object, which element is an array too. The element of element array is a config object, which defines every column field.
Code example:
- 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}
- ]]
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| title | string | The column title text. | undefined |
| field | string | The column field name. | undefined |
| width | number | The width of column. If not defined, the width will auto expand to fit its contents. | undefined |
| rowspan | number | Indicate how many rows a cell should take up. | undefined |
| colspan | number | Indicate how many columns a cell should take up. | undefined |
| align | string | Indicate how to align the column data. 'left','right','center' can be used. | undefined |
| halign | string | Indicate how to align the column header. Possible values are: 'left','right','center'. If not assigned, the header alignment is same as data alignment defined via 'align' property. This property is available since version 1.3.2. | undefined |
| sortable | boolean | True to allow the column can be sorted. | undefined |
| order | string | The default sort order, can only be 'asc' or 'desc'. This property is available since version 1.3.2. | undefined |
| resizable | boolean | True to allow the column can be resized. | undefined |
| fixed | boolean | True to prevent from adjusting width when 'fitColumns' is set to true. | undefined |
| hidden | boolean | True to hide the column. | undefined |
| checkbox | boolean | True to show a checkbox. The checkbox column has fixed width. | undefined |
| formatter | function | The cell formatter function, take three parameters: value: the field value. rowData: the row record data. rowIndex: the row index. Code example: $('#dg').datagrid({
|
undefined |
| styler | function | The cell styler function, return style string to custom the cell style such as 'background:red'. The function take three parameter: value: the field value. rowData: the row record data. rowIndex: the row index. Code example: $('#dg').datagrid({
|
undefined |
| sorter | function | The custom field sort function that used to do local sorting, take two parameters: a: the first field value. b: the second field value. Code example: $('#dg').datagrid({
|
undefined |
| editor | string,object | Indicate the edit type. When string indicates the edit type, when object contains two properties: type: string, the edit type, possible type is: text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree. options: object, the editor options corresponding to the edit type. |
undefined |
编辑器
Override defaults with $.fn.datagrid.defaults.editors.
Every editor has following actions:
| 名称 | 参数列表 | 描述 |
|---|---|---|
| init | container, options | Initialize the editor and return the target object. |
| destroy | target | Destroy the editor if necessary. |
| getValue | target | Get value from editor text. |
| setValue | target , value | Set value for editor. |
| resize | target , width | Resize the editor if necessary. |
For example, the text editor is defined as following:
- $.extend($.fn.datagrid.defaults.editors, {
- text: {
- init: function(container, options){
- var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
- return input;
- },
- destroy: function(target){
- $(target).remove();
- },
- getValue: function(target){
- return $(target).val();
- },
- setValue: function(target, value){
- $(target).val(value);
- },
- resize: function(target, width){
- $(target)._outerWidth(width);
- }
- }
- });
表格视图
Override defaults with $.fn.datagrid.defaults.view.
The view is an object that will tell datagrid how to render rows. The object must defines the following functions:
| 名称 | 参数列表 | 描述 |
|---|---|---|
| render | target, container, frozen | Called when the data is loaded. target: DOM object, the datagrid object. container: the rows container. frozen: indicate if to render the frozen container. |
| renderFooter | target, container, frozen | This is an option function to render row footer. |
| renderRow | target, fields, frozen, rowIndex, rowData | This is an option function and will be called by render function. |
| refreshRow | target, rowIndex | Defines how to refresh the specified row. |
| onBeforeRender | target, rows | Fires before the view is rendered. |
| onAfterRender | target | Fires after the view is rendered. |
事件
The events extend from panel, below is the added events for datagrid.
| 名称 | 参数列表 | 描述 |
|---|---|---|
| onLoadSuccess | data | Fires when data is loaded successfully. |
| onLoadError | none | Fires when some error occur to load remote data. |
| onBeforeLoad | param | Fires before a request is made to load data. If return false the load action will be canceled. |
| onClickRow | rowIndex, rowData | Fires when user click a row, the parameters contains: rowIndex: the clicked row index, start with 0 rowData: the record corresponding to the clicked row |
| onDblClickRow | rowIndex, rowData | Fires when user dblclick a row, the parameters contains: rowIndex: the clicked row index, start with 0 rowData: the record corresponding to the clicked row |
| onClickCell | rowIndex, field, value | Fires when user click a cell. |
| onDblClickCell | rowIndex, field, value | Fires when user dblclick a cell.
Code example: // when double click a cell, begin editing and make the editor get focus |
| onSortColumn | sort, order | Fires when user sort a column, the parameters contains: sort: the sort column field name order: the sort column order |
| onResizeColumn | field, width | Fires when user resize the column. |
| onSelect | rowIndex, rowData | Fires when user select a row, the parameters contains: rowIndex: the selected row index, start with 0 rowData: the record corresponding to the selected row |
| onUnselect | rowIndex, rowData | Fires when user unselect a row, the parameters contains: rowIndex: the unselected row index, start with 0 rowData: the record corresponding to the unselected row |
| onSelectAll | rows | Fires when user select all rows. |
| onUnselectAll | rows | Fires when user unselect all rows. |
| onCheck | rowIndex,rowData | Fires when user check a row, the parameters contains: rowIndex: the checked row index, start with 0 rowData: the record corresponding to the checked row This event is available since version 1.3. |
| onUncheck | rowIndex,rowData | Fires when user uncheck a row, the parameters contains: rowIndex: the unchecked row index, start with 0 rowData: the record corresponding to the unchecked row This event is available since version 1.3. |
| onCheckAll | rows | Fires when user check all rows. This event is available since version 1.3. |
| onUncheckAll | rows | Fires when user uncheck all rows. This event is available since version 1.3. |
| onBeforeEdit | rowIndex, rowData | Fires when user start editing a row, the parameters contains: rowIndex: the editing row index, start with 0 rowData: the record corresponding to the editing row |
| onAfterEdit | rowIndex, rowData, changes | Fires when user finish editing, the parameters contains: rowIndex: the editing row index, start with 0 rowData: the record corresponding to the editing row changes: the changed field/value pairs |
| onCancelEdit | rowIndex, rowData | Fires when user cancel editing a row, the parameters contains: rowIndex: the editing row index, start with 0 rowData: the record corresponding to the editing row |
| onHeaderContextMenu | e, field | Fires when the header of datagrid is right clicked. |
| onRowContextMenu | e, rowIndex, rowData | Fires when a row is right clicked. |
方法
| 名称 | 参数 | 描述 |
|---|---|---|
| options | none | Return the options object. |
| getPager | none | Return the pager object. |
| getPanel | none | Return the panel object. |
| getColumnFields | frozen | Return the column fields. If frozen setted to true the frozen column fields is returned. Code example: var opts = $('#dg').datagrid('getColumnFields'); // get unfrozen columns
|
| getColumnOption | field | Return the specified column option. |
| resize | param | Do resize and do layout. |
| load | param | Load and show the first page rows. If the 'param' is specified, it will replace with the queryParams property. Usually do a query by passing some parameters, this method can be called to load new data from server.
$('#dg').datagrid('load',{
|
| reload | param | Reload the rows. Same as the 'load' method but stay on current page. |
| reloadFooter | footer | Reload the footer rows. Code examples:
// update footer row values and then refresh |
| loading | none | Display loading status. |
| loaded | none | Hide loading status. |
| fitColumns | none | Make columns auto expand/collapse to fit datagrid width. |
| fixColumnSize | field | Fix columns size. If 'field' parameter is not assigned, all columns size will be fixed.
Code example: $('#dg').datagrid('fixColumnSize', 'name'); // fix the 'name' column size
|
| fixRowHeight | index | Fix the specified row height. If 'index' parameter is not assigned, all rows height will be fixed. |
| freezeRow | index | Freeze the specify row that will always be displayed at the top when the datagrid is scrolled down. This method is available since version 1.3.2. |
| autoSizeColumn | field | adjusts the column width to fit the contents. This method is available since version 1.3. |
| loadData | data | Load local data, the old rows will be removed. |
| getData | none | Return the loaded data. |
| getRows | none | Return the current page rows. |
| getFooterRows | none | Return the footer rows. |
| getRowIndex | row | Return the specified row index, the row parameter can be a row record or an id field value. |
| getChecked | none | Return all rows where the checkbox has been checked. This method is available since version 1.3. |
| getSelected | none | Return the first selected row record or null. |
| getSelections | none | Return all selected rows, when no record selected, am empty array will return. |
| clearSelections | none | Clear all selections. |
| clearChecked | none | Clear all checked rows. This method is available since version 1.3.2. |
| scrollTo | index | Scroll to the specified row. This method is available since version 1.3.3. |
| highlightRow | index | Highlight a row. This method is available since version 1.3.3. |
| selectAll | none | Select all current page rows. |
| unselectAll | none | Unselect all current page rows. |
| selectRow | index | Select a row, the row index start with 0. |
| selectRecord | idValue | Select a row by passing id value parameter. |
| unselectRow | index | Unselect a row. |
| checkAll | none | Check all current page rows. This method is available since version 1.3. |
| uncheckAll | none | Uncheck all current page rows. This method is available since version 1.3. |
| checkRow | index | Check a row, the row index start with 0. This method is available since version 1.3. |
| uncheckRow | index | Uncheck a row, the row index start with 0. This method is available since version 1.3. |
| beginEdit | index | Begin editing a row. |
| endEdit | index | End editing a row. |
| cancelEdit | index | Cancel editing a row. |
| getEditors | index | Get the specified row editors. Each editor has the following properties: actions: the actions that the editor can do, same as the editor definition. target: the target editor jQuery object. field: the field name. type: the editor type, such as 'text','combobox','datebox', etc. |
| getEditor | options | Get the specified editor, the options contains two properties: index: the row index. field: the field name. Code example: // get the datebox editor and change its value |
| refreshRow | index | Refresh a row. |
| validateRow | index | validate the specified row, return true when valid. |
| updateRow | param | Update the specified row, the param contains following properties: index: the row index to be updated. row: the new row data. Code example: $('#dg').datagrid('updateRow',{
|
| appendRow | row | Append a new row. The new row will be added to the last position:
$('#dg').datagrid('appendRow',{
|
| insertRow | param | Insert a new row, the param contains following properties: index: the row index to insert into, if not defined, append the new row. row: the row data. Code examples: // insert a new row at second row position |
| deleteRow | index | Delete a row. |
| getChanges | type | Get changed rows since the last commit. The type parameter indicate which type changed rows, possible value is: inserted,deleted,updated,etc. When the type parameter is not assigned, return all changed rows. |
| acceptChanges | none | Commits all the changes data since it was loaded or since the last time acceptChanges was called. |
| rejectChanges | none | Rolls back all the changes data since it was created, or since the last time acceptChanges was called. |
| mergeCells | options | Merge some cells to one cell, the options contains following properties: index: the row index. field: the field name. rowspan: the rowspan count to be merged. colspan: the colspan count to be merged. |
| showColumn | field | Display the specified column. |
| hideColumn | field | Hide the specified column. |
JQuery Easy Ui DataGrid的更多相关文章
- JQuery Easy Ui dataGrid 数据表格 ---制作查询下拉菜单
JQuery Easy Ui dataGrid 数据表格 数据表格 - DataGrid 继承$.fn.panel.defaults,使用$.fn.datagrid.defaults重载默认值.. 数 ...
- Jquery Easy UI Datagrid 上下移动批量保存数据
DataGrid with 上下移动批量保存数据 通过前端变量保存修改数据集合,一次性提交后台执行 本想结合easyui 自带的$('#dg').datagrid('getChanges'); 方法来 ...
- jquery Easy UI Datagrid(数据网格)学习心德,附API
第一步,引入主要的css样式和js文件 <meta http-equiv="Content-Type" content="text/html; charset=ut ...
- JQuery Easy Ui dataGrid 数据表格
数据表格 - DataGrid 英文文档:http://www.jeasyui.com/documentation/index.php# 继承$.fn.panel.defaults,使用$.fn.da ...
- JQuery Easy Ui dataGrid 数据表格 -->转
转至: http://www.cnblogs.com/cnjava/archive/2013/01/21/2869876.html#events 数据表格 - DataGrid 内容 概况 使用方法 ...
- Jquery easy ui datagrid動態加載列問題
1.如下图效果是当选择不同的日期范围时datagrid则会加载出对应的列数
- jquery easy ui datagrid中遇到的坑爹的問題。。。
; //修改 function Update() { //獲取選中行 var selected = $("#dg1").datagrid('getSelected'); //判斷是 ...
- Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏
效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- JQuery Easy Ui (Tree树)详解(转)
第一讲:JQuery Easy Ui到底是什么呢? 首先咱们知道JQuery是对Java Script的封装,是一个js库,主要提供的功能是选择器,属性修改和事件绑定等等.. JQuery ui是在j ...
随机推荐
- Oracle数据库BLOB字段的存取
述] Oracle的Blob字段比较特殊,他比long字段的性能要好很多,可以用来保存例如图片之类的二进制数据. 写入Blob字段和写入其它类型字段的方式非常不同,因为Blob自身有一个cur ...
- SpringMVC环境搭建 配置文件_2
applicationContext 命名空间: 引入命名空间,这样可以在代码中使用annotation xmlns="http://www.springframework.org/sche ...
- 为tomcat动态添加jndi数据源信息
我们在开发项目的时候,总要和数据库打交道,如何获取数据源,以什么样的方式来获取,成为了我们即简单又熟悉而且不得不注意的一个问题. 那么在这里我说三种获取数据源的常用方式: 一.通过配置文件来获取 首先 ...
- php-建造者模式(Builder)解析
其与抽象模式相类似,都可以创建复杂的对象,但是抽象工厂更注重多个系列的产品对象,而Builder模式则着重于一步一步的构建一个复杂的对象,在最后一步才返回产品, 使用建造者模式的好处是: 1.将构造代 ...
- Winmail.dat(TNEF) issue on outlook
http://www.dwheeler.com/essays/microsoft-outlook-tnef.html
- iisnode托管node
1.官方下载iisnode https://github.com/tjanczuk/iisnode 2.安装完成后在IIS中可见
- openwrt编译环境搭建
1,首先安装ubuntu系统,这里安装的是虚拟机 2,安装openwrt编译所需环境 apt-get install build-essential libncures5-dev gawk libs ...
- 【原创】安装LoadRunner12.53 版本时出现Critical error的解决方法
步骤: 1.在官网上下载LoadRunner12.53正版,只不过要注册,然后官网会给个序列号. 2.安装成功之后,快捷键已创建,打开Virtual User Generator时,提示如下错误: 此 ...
- ios 使用Core Image实现高斯模糊
在iOS和OS X平台上,Core Image都提供了大量的滤镜(Filter),这也是Core Image库中比较核心的东西之一.按照官方文档记载,在OS X上有120多种Filter,而在iOS上 ...
- jQuery 插件基础
jQuery 插件基础 翻译 How to Create a Basic Plugin 如果你需要在 jQuery 选择器上执行一系列重复操作, 这时候你需要编写 jQuery 插件. jQuery ...
