[js开源组件开发]table表格组件
table表格组件
表格的渲染组件,demo请点击http://lovewebgames.com/jsmodule/table.html,git源码请点击https://github.com/tianxiangbing/table
如上图所示,功能基本包括常用表格中遇到的分页、搜索、删除、AJAX操作。由于是用的HANDLEBARS渲染的,所以样式可能很好的控制,要加新的功能也较容易。
调用例子
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>
模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <script type= "text/x-handlebars-template" id= "tpl-list" > <table class = "tab-list" > <thead> <tr> <th class = "first-cell" >序号</th> <th>商品条码</th> <th>商品名称</th> <th>状态</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
1 2 3 4 | <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请求的类型
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库