可拖拽的datagrid

dojox.grid.DataGrid是dojo非常好用的表格控件

dojox.grid.EnhancedGrid是它的增强控件,本文通过简单的例子介绍利用插件dojox.grid.enhanced.plugins.DnD实现拖拽的表格

直接上代码

<!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">
<script type="text/javascript" src="../dojo172/dojo/dojo.js"	djConfig="parseOnLoad:true"></script>
<script>

dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojox.grid.enhanced.plugins.DnD");
dojo.ready(function(){
    /*set up data store*/
    var data = {
      identifier: 'id',
      items: []
    };
    var data_list = [
      { col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
      { col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
      { col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
    ];
    var rows = 6;
    for(var i=0, l=data_list.length; i<rows; i++){
      data.items.push(dojo.mixin({ id: i+1 }, data_list[i%l]));
    }
    var store = new dojo.data.ItemFileWriteStore({data: data});

    /*set up layout*/
    var layout = [[ //设置表头布局
      {'name': '序号', 'field': 'id', 'width': '100px'},
      {'name': '版块', 'field': 'col2', 'width': '100px'},
      {'name': '编辑', 'field': 'col3', 'width': '200px'},
      {'name': '时间', 'field': 'col4', 'width': '150px', editable:true}
    ]];

    /*create a new grid:*/
    var grid = new dojox.grid.EnhancedGrid({
        id: 'grid',
        store: store,
        structure: layout,
        rowSelector: '20px',
        canSort: function(){return false;},
        plugins: {//插件配置
            dnd: {                
                dndConfig: {}
            }
        }
      },
      document.createElement('div'));

    /*append the new grid to the div*/
    dojo.byId("gridDiv").appendChild(grid.domNode);

    /*Call startup() to render the grid*/
    grid.startup();    
});
</script>
<link rel="stylesheet" href="../dojo172/dijit/themes/claro/claro.css">
<style>
@import "../dojo172/dojox/grid/resources/Grid.css";

/*Grid need a explicit width/height by default*/
#grid {
    width: 43em;
    height: 20em;
}
</style>
<title>datagrid</title>
</head>
<body>
<div id="gridDiv"></div>
</body>
</html>

  

 

posted @ 2012-08-20 17:46  gmartincn  阅读(431)  评论(0编辑  收藏  举报