欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery仿Excel表格編輯功能的實現(xiàn)代碼

 更新時間:2013年05月01日 14:39:21   作者:  
Handsontable 是一個相當(dāng)給力的 jQuery 插件,它實現(xiàn)了 HTML 頁面中的表格編輯功能,并且是仿 Excel 的編輯效果。

  在 Excel 中可進(jìn)行的操作,你幾乎都可以在網(wǎng)頁中做到,如拖動復(fù)制、Ctrl+C 、Ctrl+V 等等。

  另外在瀏覽器支持方面,它支持以下的瀏覽器 IE7+, FF, Chrome, Safari, Opera。

如何使用:
     首先在頁面中引入 jQuery 框架和 Handsontable 插件的相關(guān) JS 和 CSS 文件,以下列出的兩個是必要的,還有其它的是可選的,如果需要某個功能時就(參看demo)加上。

復(fù)制代碼 代碼如下:

    <script src="jquery.min.js"></script>
    <script src="jquery.handsontable.full.js"></script>
    <link rel="stylesheet" href="jquery.handsontable.full.css">

  然后添加一個用于呈現(xiàn) Excel 編輯表格的 DIV 層

復(fù)制代碼 代碼如下:

<div id="example1" ></div>

  最后就可以對其進(jìn)行初始化了

復(fù)制代碼 代碼如下:

//數(shù)據(jù)
            var data = [
              {id: 1, name: "Ted", isActive: true, color: "orange"},
              {id: 2, name: "John", isActive: false, color: "black"},
              {id: 3, name: "Al", isActive: true, color: "red"},
              {id: 4, name: "Ben", isActive: false, color: "blue"}
            ];
            //黃色渲染方法
            var yellowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
              Handsontable.TextCell.renderer.apply(this, arguments);
              $(td).css({
                background: 'yellow'
              });
            };
            //綠色渲染方法
            var greenRenderer = function (instance, td, row, col, prop, value, cellProperties) {
              Handsontable.TextCell.renderer.apply(this, arguments);
              $(td).css({
                background: 'green'
              });
            };
            //初始化
            var $container = $("#example1");
            $container.handsontable({
              data: data,
              startRows: 5,
              colHeaders: true,
              minSpareRows: 1,
              columns: [
                {data: "id"},
                {data: "name", type: {renderer: yellowRenderer}}, //黃色渲染
                {data: "isActive", type: Handsontable.CheckboxCell}, //多選框
                {data: "color",
                  type: Handsontable.AutocompleteCell, //自動完成
                  source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"] //數(shù)據(jù)源
                }
              ],
              cells: function (row, col, prop) {
                if (row === 0 && col === 0) {
                  return {type: {renderer: greenRenderer}};
                }
              }
            });

注意是div容器加載完了之后進(jìn)行初始化:

demo代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic Demo</title>
    <script src="jquery.min.js"></script>
    <script src="jquery.handsontable.full.js"></script>
    <link rel="stylesheet" href="jquery.handsontable.full.css">
    <script>
        $(function(){
            //數(shù)據(jù)
            var data = [
              {id: 1, name: "Ted", isActive: true, color: "orange"},
              {id: 2, name: "John", isActive: false, color: "black"},
              {id: 3, name: "Al", isActive: true, color: "red"},
              {id: 4, name: "Ben", isActive: false, color: "blue"}
            ];
            //黃色渲染方法
            var yellowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
              Handsontable.TextCell.renderer.apply(this, arguments);
              $(td).css({
                background: 'yellow'
              });
            };
            //綠色渲染方法
            var greenRenderer = function (instance, td, row, col, prop, value, cellProperties) {
              Handsontable.TextCell.renderer.apply(this, arguments);
              $(td).css({
                background: 'green'
              });
            };
            //初始化
            var $container = $("#example1");
            $container.handsontable({
              data: data,
              startRows: 5,
              colHeaders: true,
              minSpareRows: 1,
              columns: [
                {data: "id"},
                {data: "name", type: {renderer: yellowRenderer}}, //黃色渲染
                {data: "isActive", type: Handsontable.CheckboxCell}, //多選框
                {data: "color",
                  type: Handsontable.AutocompleteCell, //自動完成
                  source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"] //數(shù)據(jù)源
                }
              ],
              cells: function (row, col, prop) {
                if (row === 0 && col === 0) {
                  return {type: {renderer: greenRenderer}};
                }
              }
            });
        });
    </script>
</head>
<body>
    <div id="example1" ></div>
</body>
</html>

相關(guān)文章

最新評論