jQuery EasyUI-DataGrid動態載入表頭

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   os   sp   for   java   

    

項目總結—jQuery EasyUI-DataGrid動態載入表頭  

目錄(?)[-]

  1. 概要
  2. 實現
  3. 總結
 

 

概要

 

       在前面兩篇文章中,我們已經介紹了在jQuery EasyUI-DataGrid中有參數和無參數的情況下將資料庫中資料顯示到前台,但是對於前面兩篇文章顯示的資料表頭是固定的,如果我們顯示到前台的資料來自資料庫不同的表,那麼表頭也需要動態載入,這篇文章我們就來看下在EasyUI-DataGrid中動態載入表頭和資料.

 

 

實現

 

        我們要實現的功能是根據我們的需要,讓DataGrid顯示不同的資料,表頭也同樣在變,我們可以先看下我們要實現功能的頁面.

 

 

我們點擊左側不同的節點,右側將會顯示不同DataGrid的資料.

 

現在我們來看下前台html頁的代碼,因為表頭是變的,所以我們的前台代碼跟前面兩篇部落格就有點不一樣了.

 

 

[html] view plaincopyprint?
  1. <divdata-optionsdivdata-options="region:‘center‘,title:‘考核對象資料錄入情況‘,iconCls:‘icon-ok‘">  
  2.                 <divclassdivclass="demo-info"data-options="fit:true,border:false,plain:true">  
  3.    
  4.                     <table id="dg"title="考核對象資料計算得分" class="easyui-datagrid"style="width: 900px; height: 400px; padding-left: 200px;"data-options="rownumbers:true,pageSize:5,pageList:[5,10,15,20],method:‘get‘,"  
  5.                        pagination="true" rownumbers="true"fitcolumns="false" striped="true"singleselect="true">  
  6.                         <thead>  
  7.                         </thead>  
  8.    
  9.                     </table>  
  10.            </div>  
  11.    
  12.         </div>  
<divdata-options="region:‘center‘,title:‘考核對象資料錄入情況‘,iconCls:‘icon-ok‘">                <divclass="demo-info"data-options="fit:true,border:false,plain:true">                     <table id="dg"title="考核對象資料計算得分" class="easyui-datagrid"style="width: 900px; height: 400px; padding-left: 200px;"data-options="rownumbers:true,pageSize:5,pageList:[5,10,15,20],method:‘get‘,"                       pagination="true" rownumbers="true"fitcolumns="false" striped="true"singleselect="true">                        <thead>                        </thead>                     </table>           </div>         </div>

 

 

 

接下來我們就看下js代碼產生表頭的代碼,的縣市區定量的表頭.

 

 

[javascript] view plaincopyprint?
  1. //縣市區定量指標計算情況查詢  
  2.            function reloadgridCityQuanty() {  
  3.                var test =document.getElementById("NodeChild").innerHTML;  
  4.   
  5.                //於一般處理常式進行互動,同時產生縣市區定量表頭  
  6.                $(‘#dg‘).datagrid({  
  7.                    url:"CalculateScoreFrameCity.ashx?test=" + test,  
  8.                    columns: [[  
  9.                    { field: ‘TargerName‘,title: ‘指標名稱‘, width: 300 },  
  10.                    { field: ‘ConditionInput‘,title: ‘資料錄入情況‘, width: 300 },  
  11.                    { field: ‘Operate‘, title:‘操作‘, width: 300 }  
  12.                    ]]  
  13.   
  14.                })  
  15.            }  
 //縣市區定量指標計算情況查詢            function reloadgridCityQuanty() {                var test =document.getElementById("NodeChild").innerHTML;                 //於一般處理常式進行互動,同時產生縣市區定量表頭                $(‘#dg‘).datagrid({                    url:"CalculateScoreFrameCity.ashx?test=" + test,                    columns: [[                    { field: ‘TargerName‘,title: ‘指標名稱‘, width: 300 },                    { field: ‘ConditionInput‘,title: ‘資料錄入情況‘, width: 300 },                    { field: ‘Operate‘, title:‘操作‘, width: 300 }                    ]]                 })            }

 

 

在這裡我們需要說下的是,我們需要將我們所有要顯示的資料的表頭都在這裡提前建立好,然後利用js語句進行動態載入.

 

我們再來看個表頭的js代碼,和上面的本質上是一樣的.

 

 

[javascript] view plaincopyprint?
  1. //縣市區定性計算情況查詢  
  2.  functionreloadgridCharacterizationCity() {  
  3.      var test =document.getElementById("NodeChild").innerHTML;  
  4.   
  5.      //於一般處理常式進行互動,同時產生縣市區定性表頭  
  6.      $(‘#dg‘).datagrid({  
  7.          url:"CalculateScoreFrameCity.ashx?test=" + test,  
  8.          columns: [[  
  9.          { field: ‘Name‘, title:‘指標名稱‘, width: 225 },  
  10.          { field: ‘ConditionInput‘,title: ‘資料錄入情況‘, width: 225 },  
  11.           { field: ‘CalculateInput‘,title: ‘計算情況‘, width: 225 },  
  12.          { field: ‘Operate‘, title:‘操作‘, width: 225 }  
  13.          ]]  
  14.   
  15.      })  
  16.   
  17.  }  
           //縣市區定性計算情況查詢            functionreloadgridCharacterizationCity() {                var test =document.getElementById("NodeChild").innerHTML;                 //於一般處理常式進行互動,同時產生縣市區定性表頭                $(‘#dg‘).datagrid({                    url:"CalculateScoreFrameCity.ashx?test=" + test,                    columns: [[                    { field: ‘Name‘, title:‘指標名稱‘, width: 225 },                    { field: ‘ConditionInput‘,title: ‘資料錄入情況‘, width: 225 },                     { field: ‘CalculateInput‘,title: ‘計算情況‘, width: 225 },                    { field: ‘Operate‘, title:‘操作‘, width: 225 }                    ]]                 })             }

 

 

 

 

關於一般處理常式的書寫與前面兩篇文章是一樣的,大家可以參考前面一篇的文章.

 

我們也來看下我們建立的另一個表頭的效果

 

 

總結

 

       通過本篇文章我們就可以在前台根據我們的需要,來建立我們需要的表頭,以此在DataGrid中顯示不同的資料.有心的同學可能注意到我們這篇文章顯示的資料與前面兩篇文章顯示的資料不一樣,前面文章DataGrid表格中顯示的資料是全部來自資料庫表,而我們這篇文章中顯示的資料不是直接來自資料庫的,是我們手動拼接成的,至於具體的實現我們在下一篇文章中進行介紹.

jQuery EasyUI-DataGrid動態載入表頭

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.