可以分列排序,隐藏的表格,异步加载 mootools
XML/HTML Code
- <div style="margin:0 auto;width:80%">
- <a href="#" onclick="grid.addRecords(newRecords);return false">Add records</a> |
- <a href="#" onclick="grid.hideColumn('address');return false">Hide Address column</a> |
- <a href="#" onclick="grid.showColumn('address');return false">Show Address column</a>
- </div>
- <div id="gridContainer" style="margin:0 auto;width:80%;"></div>
- <div id="debug"></div>
- <script type="text/javascript">
- if(!window.console){
- console = {
- log : function(obj){
- var html = $('debug').get('html');
- htmlhtml = html + obj + '<br>';
- $('debug').set('html', html);
- }
- }
- }
- function viewPlayer(id){
- try{
- console.log('View player ' + id);
- }catch(e){
- alert('View player ' + id);
- }
- }
- function previewElement(id){
- try{
- console.log('Preview ' + id);
- }catch(e){
- alert('Preview ' + id);
- }
- }
- function clickOnData(id){
- try{
- console.log('Click on ' + id);
- }catch(e){
- alert('Click on ' + id);
- }
- }
- function dblClickOnData(id){
- try{
- console.log('Double click on ' + id);
- }catch(e){
- alert('Double click on ' + id);
- }
- }
- /**
- * THE GRID OBJECT
- */
- var grid = new DG.Grid({
- title : 'Grid demo', // Title bar
- height : 500, // Height
- els : {
- parent : 'gridContainer' // Where to render the grid
- },
- behaviour : {
- resizable : true, // Grid is resizable
- closable : false // Grid is not closable
- },
- listeners : {
- 'view' : viewPlayer,
- 'load' : function(obj, gridObj){
- gridObj.setStatusText('Number of players ' + gridObj.getCountRows());
- },
- 'add' : function(obj, gridObj){
- gridObj.setStatusText('Number of players ' + gridObj.getCountRows());
- },
- 'preview' : previewElement,
- 'click' : clickOnData,
- 'dblclick' : dblClickOnData
- },
- stretch : true, // If total width of columns is less than width of view, last column will use all remaining space
- defaultSort : { /* Initial sorting */
- key : 'score',
- direction : 'asc'
- },
- statusBar : {
- visible : true
- },
- /* Column configuration */
- columnConfig : [
- {
- resizable : false,
- width : 40,
- sortable : false,
- txt : 'View',
- event : 'view',
- movable : false
- },
- {
- resizable : false,
- width : 55,
- sortable : false,
- txt : 'Preview',
- event : 'preview',
- movable : false,
- hidden : true
- },
- {
- width : 120,
- key : 'firstname',
- heading : 'First name',
- sortable : true,
- sortWith : 'lastname'
- },
- {
- width : 120,
- key : 'lastname',
- sortable : true,
- heading : 'Last name',
- sortWith : 'firstname'
- },
- {
- width : 70,
- align : 'right',
- key : 'score',
- sortable : true,
- removable : false,
- heading : 'Score',
- renderer : function(val){
- if(val == 0){
- return val;
- }else if(val > 0){
- return '<span style="color:#F00">' + val + '</span>';
- }else{
- return '<span style="color:#060">' + val + '</span>';
- }
- }
- },
- {
- hidden : true,
- width : 200,
- key : 'address',
- sortable : true,
- removable : true,
- heading : 'Address'
- },
- {
- width : 90,
- key : 'zip',
- sortable : true,
- removable : true,
- heading : 'Zip code'
- },
- {
- width : 300,
- key : 'city',
- sortable : true,
- removable : true,
- heading : 'City'
- },
- {
- width : 100,
- key : 'birth',
- sortable : true,
- removable : true,
- heading : 'Born'
- }
- ],
- remote : {
- url : 'datasource/grid-data.php'
- }
- });
- /** END GRID CONFIG */
- /* Config objects for two new dynamically added records */
- var newRecords = [
- {
- id : 1000,
- firstname : 'Tiger',
- lastname : 'Woods(New record)',
- address : 'NEW ADDRESS',
- zip : '9999',
- city : 'LONDON',
- score : -21,
- birth : '<i style="display:none">1991-08-11</i>Sun, August 11, 1991'
- },
- {
- id : 1001,
- firstname : 'Rory',
- lastname : 'McIlroy(New Record)',
- address : 'NEW ADDRESS 2',
- zip : '9998',
- city : 'LONDON',
- score : -20,
- birth : '<i style="display:none">1991-08-12</i>Mon, August 12, 1991'
- }
- ]
- </script>
原文地址:http://www.freejs.net/article_jquerywenzi_111.html