萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> DivCSS教程 >> Ext.grid.GridPanel單元格特殊設置

Ext.grid.GridPanel單元格特殊設置


<html>
    <head>
        <title>03.grid</title>
        <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
        <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
        <script type="text/javascript" src="../../ext-all.js"></script>
        <script type="text/javascript">
Ext.onReady(function(){
    //只使用第一個參數
    function renderSex(value) {
        if (value == 'male') {
            return "<span style='color:red;font-weight:bold;'>紅男</span><img src='user_male.png' />";
        } else {
            return "<span style='color:green;font-weight:bold;'>綠女</span><img src='user_female.png' />";
        }
    }
    //使用了所有的參數
    function renderDescn(value, cellmeta, record, rowIndex, columnIndex, store) {
        var str = "<input type='button' value='查看詳細信息' onclick='alert("" +
            "這個單元格的值是:" + value + "n" +
            "這個單元格的配置是:{cellId:" + cellmeta.cellId + ",id:" + cellmeta.id + ",css:" + cellmeta.css + "}n" +
            "這個單元格對應行的record是:" + record + ",一行的數據都在裡邊n" +
            "這是第" + rowIndex + "行n" +
            "這是第" + columnIndex + "列n" +
            "這個表格對應的Ext.data.Store在這裡:" + store + ",隨便用吧。" +
            "")'>";
        return str;
    }
 
    var cm = new Ext.grid.ColumnModel([
        {header:'編號',dataIndex:'id'},
        {header:'性別',dataIndex:'sex', renderer:renderSex},
        {header:'名稱',dataIndex:'name'},
        {header:'描述',dataIndex:'descn', width:200, renderer:renderDescn}
    ]);
 
    var data = [
        ['1','male','name1','descn1'],
        ['2','female','name2','descn2'],
        ['3','male','name3','descn3'],
        ['4','female','name4','descn4'],
        ['5','male','name5','descn5']
    ];
 
    var store = new Ext.data.Store({
        proxy: new Ext.data.MemoryProxy(data),
        reader: new Ext.data.ArrayReader({}, [
            {name: 'id'},
            {name: 'sex'},
            {name: 'name'},
            {name: 'descn'}
        ])
    });
    store.load();
 
    var grid = new Ext.grid.GridPanel({
        autoHeight: true,
        renderTo: 'grid',
        store: store,
        cm: cm
    });
 
});
        </script>
    </head>
    <body>
        <div id="grid"></div>
    </body>
</html>



Ext.grid.GridPanel單元格特殊設置 三聯

copyright © 萬盛學電腦網 all rights reserved