javascript表格的渲染组件

表格的渲染组件,demo请点击,git源码请点击https://github.com/tianxiangbing/table

如上图所示,功能基本包括常用表格中遇到的分页、搜索、删除、AJAX操作。由于是用的HANDLEBARS渲染的,所以样式可能很好的控制,要加新的功能也较容易。

调用例子

html

<div> 名称: <input type="text"> <a href="#">search</a> </div> <div ajaxurl="list.json"> loading... </div> <div></div>

模板

<script type="text/x-handlebars-template"> <table> <thead> <tr> <th>序号</th> <th>商品条码</th> <th>商品名称</th> <th>状态</th> <th>操作</th> </tr> </thead> <tbody> {{#each data}} <tr> <td>{{@index}}</td> <td>{{goods_bn}}</td> <td>{{goods_name}}</td> <td>上架</td> <td><a js-ajax-param="id={{goods_id}}" href="https://www.jb51.net/action.json">下架</a> <a href="https://www.jb51.net/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)


构造函数,table是指存放表格的容器,可以是一个空的div,也可以是table里的一个tbody;
temp是指表格的模板,这里是script节点的jquery对象
page 需要放置分页控件的容器
param 初始化带的参数 type json
search 搜索按钮节点,你的祖先级中要有一个class为form的节点,会利用[query](https://github.com/tianxiangbing/query)格式化里面为参数,进行查询数据操作
callback 加载后的回调
filterCon 筛选过滤

init:function(settings)
init是启动方法,目前的settings中仅包含{type:'get'} ,ajax请求的类型

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgdddf.html