Class Index | File Index

Classes


Class SortView

用于显示排序按钮/链接的控件, 并包含 js 排序功能. 这些排序控件附加在指定的 HTMLElement 里.
Defined in: SortView.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
Field Attributes Field Name and Description
 
排序字段的名字.
 
可供排序的字段哈希表, 字段对应一个数组, 数组格式为[类型, 比较函数].
 
排序方向, 取值为: asc|desc.
Method Summary
Method Attributes Method Name and Description
 
onclick(field, order)
用户重写本方法, 获取排序事件.
 
render(elements)
进行渲染.
 
sort(rows)
根据当前的字段和方向, 对对象数组进行排序.
Class Detail
SortView()

Author: ideawu@163.com.
var rows = []; // datasource

var sort = new SortView();
sort.fields = {
	'id'	: ['int', null],
	'name'	: [null, null]
};

var elements = {};
var ths = $('table th').each(function(i, th){
	var k = $(th).attr('field');
	if(k != undefined){
		elements[k] = th;
	}
});
sort.onclick = function(){
	sort.sort(rows);
	// do with rows...
}

sort.render(elements);
Returns:
{SortView} : 返回排序控件实例.
Requires:
jQuery PagerView SortView
See:
http://www.ideawu.net/
Field Detail
{String} field
排序字段的名字.

{Object} fields
可供排序的字段哈希表, 字段对应一个数组, 数组格式为[类型, 比较函数]. 当类型为: null|int|date|text|string|float 且不指定比较函数时, 使用默认的比较函数.

{String} order
排序方向, 取值为: asc|desc.
Method Detail
{Boolean} onclick(field, order)
用户重写本方法, 获取排序事件.
Parameters:
{String} field
排序字段.
{String} order
排序方向.
Returns:
{Boolean} 返回false表示取消本次排序事件.

render(elements)
进行渲染.
Parameters:
{Object} elements
哈希表, 字段名与HTMLElement的对应关系.

sort(rows)
根据当前的字段和方向, 对对象数组进行排序.
Parameters:
rows

Documentation generated by JsDoc Toolkit 2.3.0 on Sat Oct 23 2010 16:24:07 GMT+0800 (CST)