JsGrid官网地址:http://js-grid.com/
JsGrid是一款很轻便的表格插件,适用于各种小型CMS的开发。起初使用的时候,一旦遇到问题基本百度不到解决方法,而官网也需要翻墙才能看到完整内容。于是使用某软件将官网download成了本地html文件,有需要的看官可以到我的资源页进行下载,这是地址:http://download.csdn.net/detail/qq_28550739/9752728。
这是官网提供的CDN地址,我没有尝试过,所以无法得知其访问速度。
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
1.下载插件资源包,官网有下载地址,在我的资源页中也有提供下载:http://download.csdn.net/detail/qq_28550739/9752730。
2. 确保项目中的jQuery版本在1.8及以上,也就是说必须先引入1.8及以上版本的jQuery。
3. 引入jsGrid的js与css文件
<link type="text/css" rel="stylesheet" href="jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="jsgrid-theme.min.css" />
<script type="text/javascript" src="jsgrid.min.js"></script>
4.在body中添加一个div,并设置id为jsGrid,这里的id可以自定义,只需要在后面初始化时保持一致即可。
5.在script中对jsGrid进行初始化
<script>
var clients = [
{ "Name": "Otto Clay", "Age": 25, "Country": 1, "Address": "Ap #897-1459 Quam Avenue", "Married": false },
{ "Name": "Connor Johnston", "Age": 45, "Country": 2, "Address": "Ap #370-4647 Dis Av.", "Married": true },
{ "Name": "Lacey Hess", "Age": 29, "Country": 3, "Address": "Ap #365-8835 Integer St.", "Married": false },
{ "Name": "Timothy Henson", "Age": 56, "Country": 1, "Address": "911-5143 Luctus Ave", "Married": true },
{ "Name": "Ramona Benton", "Age": 32, "Country": 3, "Address": "Ap #614-689 Vehicula Street", "Married": false }
];
var countries = [
{ Name: "", Id: 0 },
{ Name: "United States", Id: 1 },
{ Name: "Canada", Id: 2 },
{ Name: "United Kingdom", Id: 3 }
];
$("#jsGrid").jsGrid({
width: "100%",
height: "400px",
inserting: true,
editing: true,
sorting: true,
paging: true,
data: clients,
fields: [
{ name: "Name", type: "text", width: 150, validate: "required" },
{ name: "Age", type: "number", width: 50 },
{ name: "Address", type: "text", width: 200 },
{ name: "Country", type: "select", items: countries, valueField: "Id", textField: "Name" },
{ name: "Married", type: "checkbox", title: "Is Married", sorting: false },
{ type: "control" }
]
});
</script>
一个最简单的jsGrid表格就绘制成功了。
当然, 它支持很多功能,比如批量删除、ajax动态加载、分页、条件查询、排序等,如果有时间的话会在后面一一详细说明。