<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

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


    網站導航:
     
    主站蜘蛛池模板: 国产91精品一区二区麻豆亚洲| 亚洲一区二区免费视频| 国产在线观看免费完整版中文版| 亚洲中文无码线在线观看| 免费A级毛片av无码| 久久国产精品亚洲综合| 久久一区二区三区免费播放| 亚洲AV无码码潮喷在线观看| 野花香高清视频在线观看免费| 亚洲国产成人私人影院| 91精品免费高清在线| 亚洲AV无码乱码在线观看代蜜桃 | 亚洲欧美日本韩国| 国产美女精品久久久久久久免费| 国产精品亚洲小说专区| 国产亚洲精品看片在线观看 | 亚洲不卡AV影片在线播放| 中文字幕无线码中文字幕免费| 国产精品亚洲片在线观看不卡| 100部毛片免费全部播放完整| 亚洲1区1区3区4区产品乱码芒果 | 免费人成再在线观看网站| MM131亚洲国产美女久久| 人人玩人人添人人澡免费| 亚洲一区二区三区亚瑟| 亚洲国产精品视频| 久久久精品2019免费观看| 亚洲日韩看片无码电影| 久久亚洲国产成人精品无码区| 无码专区AAAAAA免费视频| 亚洲综合无码无在线观看| JLZZJLZZ亚洲乱熟无码| 久久九九兔免费精品6| 日韩亚洲人成在线综合| 久久青草亚洲AV无码麻豆| 免费看a级黄色片| 成全视频在线观看免费| 亚洲精品无码专区| 久久久久亚洲AV片无码| 在线观看视频免费国语| 久久青青草原国产精品免费|