SlickGrid example 1: 最简单的例子和用法

SlickGrid例子和用法

开始学习使用SlickGrid,确实挺好用,挺方便的。

官网地址: https://github.com/mleibman/SlickGrid
不多说,先上效果图。
SlickGrid example 1: 最简单的例子和用法
上代码。(源码)
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SlickGrid example 1: Basic grid</title>
<link rel="stylesheet" href="../css/slick.grid.css" type="text/css" />
<link rel="stylesheet" href="../css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css" />
<link rel="stylesheet" href="../css/examples.css" type="text/css" />
</head>
<body>
<table width="100%">
  <tr>
    <td valign="top" width="50%">
      <div id="myGrid" style="width:600px;height:500px;"></div>
    </td>
    <td valign="top">
      <h2>Demonstrates:</h2>
      <ul>
        <li>basic grid with minimal configuration</li>
      </ul>
    </td>
  </tr>
</table>
 
<script src="../js/jquery-1.7.min.js"></script>
<script src="../js/jquery.event.drag-2.0.min.js"></script>
<script src="../js/slick.core.js"></script>
<script src="../js/slick.grid.js"></script>
 
<script type="text/javascript">
var grid;//定义表格
//设置列,name为表头显示名称,field为对应域的名字
var columns = [
      {id: "title", name: "Title", field: "title"},
      {id: "duration", name: "Duration", field: "duration"},
      {id: "%", name: "% Complete", field: "percentComplete"},
      {id: "start", name: "Start", field: "start"},
      {id: "finish", name: "Finish", field: "finish"},
      {id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
    ];
//设置表格参数
var options = {
   enableCellNavigation: true,
   enableColumnReorder: false
 };
//定义表格数据变量
var data = [];
$(function () {
//生成表格数据
   for (var i = 0; i < 100; i++) {
     data[i] = {
       title: "Task " + i,
       duration: "5 days",
       percentComplete: Math.round(Math.random() * 100),
       start: "01/01/2012",
       finish: "01/05/2012",
       effortDriven: (i % 5 == 0)
     };
   }
//创建grid,“myGrid”为表格生成位置的ID
   grid = new Slick.Grid("#myGrid", data, columns, options);
 });
//定时刷新表格数据
setInterval(function(){
var rows = Math.round(Math.random() * 100);
data = [];
for (var i = 0; i < rows; i++) {
     data[i] = {
       title: "Task " + i,
       duration: "5 days",
       percentComplete: Math.round(Math.random() * 100),
       start: "01/01/2012",
       finish: "01/05/2012",
       effortDriven: (i % 5 == 0)
     };
   }
//重新渲染表格
grid.setData(data);
grid.updateRowCount();
grid.render();
},5000);
</script>
</body>
</html>
上一篇:STL heap usage


下一篇:python 代码片段21