datagrid進階——subGrid講解,datagridsubgrid

來源:互聯網
上載者:User

datagrid進階——subGrid講解,datagridsubgrid

subGrid,也就是datagrid中再套一層datagrid,比較適合用於顯示一些帶有層次的資料,比如要顯示一批訂單,訂單包含具體的貨物。這樣一個需求,就可以用到subGrid。

我們可以先看看官網上subGrid的樣子來增強一下視覺上的感覺。


如何來實現呢?若只是用來顯示一下資料,其實還是簡單的。

看看demo的代碼量也不過區區幾十行,跟上思路很容易就可以理解了。

        $(function(){            $('#dg').datagrid({                view: detailview,                detailFormatter:function(index,row){                    return '<div style="padding:2px"><table class="ddv"></table></div>';                },                onExpandRow: function(index,row){                    var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');                    ddv.datagrid({                        url:'datagrid22_getdetail.php?itemid='+row.itemid,                        fitColumns:true,                        singleSelect:true,                        rownumbers:true,                        loadMsg:'',                        height:'auto',                        columns:[[                            {field:'orderid',title:'Order ID',width:200},                            {field:'quantity',title:'Quantity',width:100,align:'right'},                            {field:'unitprice',title:'Unit Price',width:100,align:'right'}                        ]],                        onResize:function(){                            $('#dg').datagrid('fixDetailRowHeight',index);                        },                        onLoadSuccess:function(){                            setTimeout(function(){                                $('#dg').datagrid('fixDetailRowHeight',index);                            },0);                        }                    });                    $('#dg').datagrid('fixDetailRowHeight',index);                }            });        });

1、使用這個subGrid的視圖,需要使用到官網提供的datagrid-detailview.js,其中幫我們定義好了detailView這種顯示視圖。

在使用過程中,我們只需要在主datagrid中將預設的view用detailView替換掉就可以了。

2、detailFormatter,也就是產生的detail中的初始代碼,這裡放入一個table,之後可以將其動態建立成datagrid。

3、當主datagrid剛剛初始化完成時,並不顯示subGrid,此時subGrid並沒有存在的必要,我們也不去建立它。

那什麼時候去建立它呢?當我們展開主datagrid中的某條資料的時候,也就是在onExpandRow事件中,才去建立一個它“管轄”的subGrid。

4、建立subGrid的方法和一般建立datagrid的方式差不多,但是後面多了一些fixDetailRowHeight的操作

fixDetailRowHeight這個方法主要是為了調整subGrid的高度用的,如若不加,可能會造成subGrid的高度會出現錯位的情況。


不過這裡setTimeout的時間為0,那和直接調用function又有什麼區別呢?


silverlight datagrid 顯示選擇excel檔案的內容

用ASPX頁面 就行了,不要用銀光

Private Sub excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

With Response
.Buffer = True
.ContentType = "application/vnd.ms-excel "
.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ")
End With

DataGrid_CXMONEY.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
DataGrid_CXMONEY.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

end sub

GRID在放在ASPX頁面上,綁定資料來源

這樣匯出非常快,比自己遞迴填充XLS儲存格不知道快多少.
但有個缺陷就是只能看,做統計時會有問題.
因為其實這段代碼原理就是用XLS中顯示HMTL而已,跟真正的XLS原始碼有區別的

 
silverlight中的datagrid匯出excel

用ASPX頁面 就行了,不要用銀光

Private Sub excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

With Response
.Buffer = True
.ContentType = "application/vnd.ms-excel "
.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ")
End With

DataGrid_CXMONEY.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
DataGrid_CXMONEY.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

end sub

GRID在放在ASPX頁面上,綁定資料來源

這樣匯出非常快,比自己遞迴填充XLS儲存格不知道快多少.
但有個缺陷就是只能看,做統計時會有問題.
因為其實這段代碼原理就是用XLS中顯示HMTL而已,跟真正的XLS原始碼有區別的
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.