<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    當柳上原的風吹向天際的時候...

    真正的快樂來源于創造

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
    http://www.cnblogs.com/evilyang/archive/2012/02/17/2355218.html

    一、使用場景

       服務端獲得的DataTable轉化為Json格式后傳遞給客戶端dojo,dojo將json數據直接綁定在dojox.grid.DataGrid上

    二、基本用法

    1.客戶端頁面DataToJson.aspx返回一個Json數據

    復制代碼
        private void Json()
        {
            DataTable dt = this.GetData();
            string str = JsonHelper.DateTableToJson(dt);
            Response.Write(str);
            Response.End();
        }
    復制代碼
     2.利用ajax接受json數據

    dojox.grid.DataGrid憑借dojo.data.ItemFileWriteStore可以輕松具有ajax功能

    使用dojo.grid.DataGrid首先做如下準備工作

    a.引入樣式表

    <link rel="Stylesheet" href="dojo-re/dojox/grid/resources/soriaGrid.css" />
    b.引入所需庫
    dojo.require("dojo.parser");
    dojo.require("dijit.form.Button"); 
    dojo.require("dojox.grid.DataGrid");

    dojo.require("dojo.data.ItemFileWriteStore");

    dojo.require("dojox.layout.FloatingPane");
    c.編寫代碼
    復制代碼
    <script type="text/javascript">
            function Grid1() {
                var data = new dojo.data.ItemFileWriteStore({
                    url: "DataToJson.aspx"
                });
                var structure = [
                    { name: "用戶名", field: "userName", width: "120px" },
                    { name: "密碼", field: "userPwd", width: "120px" },
                    { name: "電子郵件", field: "email", width: "150px;" },
                    { name: "博客", field: "blog", width: "150px" },
                    { name: "生日", field: "birthday", width: "120px" },
                    { name: "年齡", field: "age", width: "80px" },
                    { name: "備注", field: "description", width: "120px" }
                ];
                var grid = new dojox.grid.DataGrid({
                store: data,
                structure:structure
                },"grid1");
                grid.startup();
            }
            function ShowFloatingPane() {
                var floatingPane = dijit.byId("dFloatingPane");
                floatingPane.show();
                Grid1();
            }
        </script>
    復制代碼

     所需HTML

    復制代碼
       <div >
            <div data-dojo-type="dojox.layout.FloatingPane" id="dFloatingPane"
               title
    ="A floating pane" data-dojo-props="resizable:true, dockable:true, title:'A floating pane'"
               style
    ="position:absolute;top:150px;left:400px;width:600px;height:400px; visibility:hidden">
                 <div id="grid1" style="width:450px; height:350px"></div>
            </div>
        </div>
    <div data-dojo-type="dijit.form.Button" data-dojo-props="label:'Show me', onClick:ShowFloatingPane"></div>
     
    復制代碼

     d.運行結果如下:

     

     三、繼續完善DataGrid功能

    1,增加搜索條件

    query:{userName:"evilyang",id:"*"},

     2,隱藏一列,不顯示

     {name:"密碼",field:"userPwd",width:"100px",hidden:"true"}

    3,為某一列增加一個樣式名

     <style type="text/css">
        .name{ font-style:italic; font-size:14px; color:Red;}
        </style>
    { name: "用戶名", field: "userName", width: "120px" ,classes:"name"}
     4,為某一列直接增加一個樣式
    { name: "電子郵件", field: "email", width: "150px;",styles:"text-align:center;" },
    5,固定前兩列

    更改structure結構,加入noscroll屬性

    復制代碼
    var structure = [{
                    noscroll: true,
                    cells: [
                    { name: "用戶名", field: "userName", width: "80px", classes: "name" },
                    { name: "密碼", field: "userPwd", width: "80px", hidden: "true" },
                    { name: "電子郵件", field: "email", width: "150px;", styles: "text-align:center;" }    
                    ]
                }, {
                    cells: [
                    { name: "博客", field: "blog", width: "120px" },
                    { name: "生日", field: "birthday", width: "120px" },
                    { name: "年齡", field: "age", width: "50px" },
                    { name: "備注", field: "description", width: "120px" }
                    ]
                }];
    復制代碼

     6,cell中的樣式設置默認模式

    defaultCell:{width:"80px",styles:"text-align:center;"},
     這樣設置完后,每一列的屬性就不必單獨設置了

    7, 其他屬性

    selectionMode: "extended", //none,single,multiple
    loadingMessage: "請等待,數據正在加載中......",
     errorMessage: "對不起,你的請求發生錯誤!",
     columnReordering:true//此屬性設置為true,可以拖拽標題欄,更換列順序

    new dojox.grid.cells.RowIndex({ name: "編號", width: "20px" })//加入自編號

    四、數據顯示高級功能

    1, RowClick事件

    復制代碼
    grid.on("RowClick", function(evt) {
                    var idx = evt.rowIndex,
                        item = this.getItem(idx),
                        store = this.store;
                        content = dojo.byId("content");
                        content.innerHTML="you have clicked on rows " + store.getValue(item, "id");
              }, true);
    復制代碼

     2,SelectionChanged事件

    復制代碼
    grid.on("SelectionChanged",dojo.hitch(grid, reportSelection), true);
    function reportSelection() {
                var items = this.selection.getSelected(),
                            msg = "你選擇了以下數據";
                var tmp = dojo.map(items, function(item) {
                    return this.store.getValue(item, "id");
                }, this);
                var content = dojo.byId("content");
                content.innerHTML = msg + tmp.join(",");
               
            }
    復制代碼

    五、顯示效果如下圖:


    posted on 2013-02-18 17:09 何楊 閱讀(3933) 評論(0)  編輯  收藏 所屬分類: Dojo

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 日本成年免费网站| 国产卡一卡二卡三免费入口| 免费人成在线观看网站视频| 99热亚洲色精品国产88| 免费电影在线观看网站| 亚洲H在线播放在线观看H| 两性刺激生活片免费视频| 亚洲一级免费视频| 在线a毛片免费视频观看| 色综合久久精品亚洲国产| 国产成人啪精品视频免费网| 国产成人亚洲精品播放器下载| 免费观看国产小粉嫩喷水| 人体大胆做受免费视频| 国产亚洲精品a在线观看| 国产一区二区三区免费观在线| 亚洲精品成人网站在线观看 | 国产亚洲?V无码?V男人的天堂| 九九综合VA免费看| 国产亚洲综合久久系列| 99爱在线精品视频免费观看9| 亚洲国产精品无码久久久| 香蕉高清免费永久在线视频| 婷婷亚洲综合一区二区| 亚洲熟妇av一区二区三区漫画| 亚洲视频免费在线观看| 亚洲午夜无码久久久久小说| 午夜亚洲国产成人不卡在线| a毛片在线免费观看| 精品亚洲AV无码一区二区三区| 日本一区免费电影| 少妇性饥渴无码A区免费| 亚洲一区免费在线观看| 午夜亚洲国产成人不卡在线| 日本免费中文字幕| 亚洲精品美女久久7777777| 亚洲乱码精品久久久久..| 国产在线观看免费观看不卡| 青青青视频免费观看| 亚洲国产综合在线| 中文字幕亚洲综合久久男男|