javascript表格的渲染組件
表格的渲染組件,demo請(qǐng)點(diǎn)擊http://lovewebgames.com/jsmodule/table.html,git源碼請(qǐng)點(diǎn)擊https://github.com/tianxiangbing/table
如上圖所示,功能基本包括常用表格中遇到的分頁(yè)、搜索、刪除、AJAX操作。由于是用的HANDLEBARS渲染的,所以樣式可能很好的控制,要加新的功能也較容易。
調(diào)用例子
html
<div class="form"> 名稱: <input type="text" name="gname"> <a href="#" id="search">search</a> </div> <div id="tab-list" ajaxurl="list.json"> loading... </div> <div id="pager"></div>
模板
<script type="text/x-handlebars-template" id="tpl-list">
<table class="tab-list">
<thead>
<tr>
<th class="first-cell">序號(hào)</th>
<th>商品條碼</th>
<th>商品名稱</th>
<th>狀態(tài)</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{{#each data}}
<tr>
<td class="first-cell">{{@index}}</td>
<td>{{goods_bn}}</td>
<td>{{goods_name}}</td>
<td>上架</td>
<td><a class="js-ajax" js-ajax-param="id={{goods_id}}" href="action.json">下架</a> <a class="js-delete" href="action.json">刪除</a></td>
</tr>
{{/each}}
</tbody>
</table>
</script>
js
<script>
var table = new Table($('#tab-list'), $('#tpl-list'), $('#pager'), {}, $('#search'));
table.init({type:'post'});
</script>
屬性和方法
constuctor:function(table, temp, page, param, search, callback, filterCon)
構(gòu)造函數(shù),table是指存放表格的容器,可以是一個(gè)空的div,也可以是table里的一個(gè)tbody;
temp是指表格的模板,這里是script節(jié)點(diǎn)的jquery對(duì)象
page 需要放置分頁(yè)控件的容器
param 初始化帶的參數(shù) type json
search 搜索按鈕節(jié)點(diǎn),你的祖先級(jí)中要有一個(gè)class為form的節(jié)點(diǎn),會(huì)利用[query](https://github.com/tianxiangbing/query)格式化里面為參數(shù),進(jìn)行查詢數(shù)據(jù)操作
callback 加載后的回調(diào)
filterCon 篩選過濾
init:function(settings)
init是啟動(dòng)方法,目前的settings中僅包含{type:'get'} ,ajax請(qǐng)求的類型
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
相關(guān)文章
Highslide.js是一款基于js實(shí)現(xiàn)的網(wǎng)頁(yè)中圖片展示插件
這篇文章主要介紹了Highslide.js是一款基于js實(shí)現(xiàn)的網(wǎng)頁(yè)中圖片預(yù)覽查看工具,需要的朋友可以參考下2007-05-05
JavaScript指定字段排序方法sortFun函數(shù)
這篇文章主要介紹了JavaScript指定字段排序方法sortFun函數(shù),數(shù)組的排序方法是sort,但是它并不支持根據(jù)指定的字段進(jìn)行排序,而sortFun可以根據(jù)指定的字段進(jìn)行排序,需要的朋友可以參考下2023-05-05
javascript網(wǎng)頁(yè)關(guān)鍵字高亮代碼
非常不錯(cuò)的關(guān)鍵字高亮代碼,用js實(shí)現(xiàn),這個(gè)方法不錯(cuò)2008-07-07

