jquery樹形表格實現方法

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   ar   java   for   

 

準備步驟:

具體使用的Dome可以在這個位置下載

http://download.csdn.net/detail/jine515073/7986227

1.引入jquery.treeTable.js和jquery.treeTable.css

前台代碼如下:

<head runat="server">    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <link href="/resources/js/treeTable/vsStyle/jquery.treeTable.css" rel="stylesheet" type="text/css" />    <style type="text/css">        table, td, th {            border: 1px solid #8DB9DB;            padding: 5px;            border-collapse: collapse;            font-size: 16px;        }    </style>    <script src="/resources/js/jquery-1.7.2.min.js" type="text/javascript"> </script>    <script src="/resources/js/treeTable/jquery.treeTable.js" type="text/javascript"> </script>    <script type="text/javascript">        $(function () {            var option = {                theme: ‘vsStyle‘,                expandLevel: 2,                beforeExpand: function ($treeTable, id) {                    //判斷id是否已經有了孩子節點,如果有了就不再載入,這樣就可以起到緩衝的作用                    if ($(‘.‘ + id, $treeTable).length) { return; }                    //這裡的html可以是ajax請求                    //var html = ‘<tr id="8" pId="6"><td>員工夥食費</td><td>5000</td><td>1000</td></tr>‘                    $treeTable.addChilds(html);                },                onSelect: function ($treeTable, id) {                    window.console && console.log(‘onSelect:‘ + id);                }            };            $(‘#treeTable1‘).treeTable(option);        });    </script></head><body>    <form id="form1" runat="server">        <div>            <table id="treeTable1" style="width: 100%">                <asp:Repeater ID="Repeater1" runat="server" >                    <HeaderTemplate>                        <tr>                            <td style="width: 200px;">收支項目</td>                        </tr>                    </HeaderTemplate>                    <ItemTemplate>                        <tr id="<%#Eval("pid") %>" pid="<%#Eval("fatherid") %>">                            <td><%#Eval("Categories") %></td>                        </tr>                    </ItemTemplate>                </asp:Repeater>             </table>        </div>    </form></body></html>

後台代碼:

DataTable dt = new DataTable();dt.Columns.Add("pid");dt.Columns.Add("fatherid");dt.Columns.Add("Categories");dt.Columns.Add("Month");dt.Columns.Add("Year");this.Repeater1.DataSource = dt;this.Repeater1.DataBind();

細心的朋友會發現,多級資料,在資料庫是沒有按照上下級排序好的,但是這個控制項需要按照上下級排序正確後,才能正常顯示,所以要補充一個資料庫排序的代碼

with cte(SortID,CategoryID,CategoryName,ParentID) as (select cast(row_number() over(order by CategoryID) as varchar(10)) SortID,CategoryID,CategoryName,ParentID fromCategory where ParentID=0 and [email protected] AND Type=4union allselect  cast(SortID+cast(row_number() over(order by a.CategoryID)as varchar(10)) as varchar(10)),a.CategoryID,a.CategoryName,a.ParentIDfrom Category a join cte on cte.CategoryID=a.ParentID )
select  CategoryID,CategoryName,ParentID from cte  order by SortID

 

jquery樹形表格實現方法

聯繫我們

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