2012-01-11 12 views
6

私は、スクロール時に固定ヘッダーを持つグリッドビューを実装しようとしていましたが、ヘッダー列をクリックすると並べ替えることもできます。しばらく検索した後、私は自分のサイトで完璧に動作する素晴らしいソリューションをオンラインで見つけました。同じ質問がある場合は、こちらをチェックしてください - http://www.aspsnippets.com/Articles/Scrollable-GridView-with-Fixed-Headers-and-Client-Side-Sorting-using-jQuery-in-ASP.Net.aspxソート機能付きの固定ヘッダーグリッド

私はそれをソートしようとしましたが、それは自分のページに置くと機能しませんでした。

ここに私の質問があります:複数の列を並べて並べ替えることができるようにしたいと考えていました。サイトのコードでは、単一の列の並べ替えしかできません。誰かがソートの第2レベルを追加する方法に関する提案を持っていますか?

ここ

が私のコードです:C#で

<script type = "text/javascript"> 
    $(document).ready(function() { 
     $("#<%=ChangedUPCs2.ClientID%>").tablesorter(); 
     SetDefaultSortOrder(); 
    }); 

    function Sort(cell, sortOrder) { 
     var sorting = [[cell.cellIndex, sortOrder]]; 
     $("#<%=ChangedUPCs2.ClientID%>").trigger("sorton", [sorting]); 
     if (sortOrder == 0) { 
      sortOrder = 1; 
      cell.className = "sortDesc"; 
     } 
     else { 
      sortOrder = 0; 
      cell.className = "sortAsc"; 
     } 
     cell.setAttribute("onclick", "Sort(this, " + sortOrder + ")"); 
     cell.onclick = function() { Sort(this, sortOrder); }; 
     document.getElementById("container").scrollTop = 0; 
    } 

    function SetDefaultSortOrder() { 
     var gvHeader = document.getElementById("dummyHeader"); 
     var headers = gvHeader.getElementsByTagName("TH"); 
     for (var i = 0; i < headers.length; i++) { 
      headers[i].setAttribute("onclick", "Sort(this, 1)"); 
      headers[i].onclick = function() { Sort(this, 1); }; 
      headers[i].className = "sortDesc"; 
     } 
    } 

<table id="dummyHeader" cellspacing="0" rules="all" border="1" style="width: 800px; border-collapse:collapse;" class = "grid"> 
      <thead> 
      <tr> 
       <th scope="col" style="width: 30px;">Tier</th> 
       <th scope="col" style="width: 75px;">UPC</th> 
       <th scope="col" style="width: 50px;">Line Code</th> 
       <th scope="col" style="width: 100px;">Brand</th> 
       <th scope="col" style="width: 205px;">Product</th> 
       <th scope="col" style="width: 70px;">Old Qty/Old Price</th>      
       <th scope="col" style="width: 70px;">New Qty/New Price</th> 

       <th scope="col" style="width: 50px;">Cost</th> 
       <th scope="col" style="width: 50px;">Old Margin</th> 
       <th scope="col" style="width: 50px;">New Margin</th> 
       <th scope="col" style="width: 50px;">Tag Type</th> 
       <th scope="col" style="width: 50px;">Effective Date</th> 
      </tr> 
      </thead> 
     </table> 

     <div id="container" style="height:200px; overflow: auto; width: 817px;"> 
       <asp:GridView ID="ChangedUPCs2" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="banner,enterprise_zone,UPC,ProductDescriptionLong" 
        DataSourceID="Changes2" class="styleGrid" ondatabound="ChangedUPCs2GridDataBound" 
        Width = "800px" ViewStateMode = "Disabled"> 
        <Columns> 
         <asp:TemplateField HeaderText="Tier" ItemStyle-Width="30px"> 
          <ItemTemplate> 
           <asp:Label ID="Tier" Text='<%# Eval("enterprise_zone") %>' runat="server" class="zn"/> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:BoundField DataField="UPC" HeaderText="UPC" ItemStyle-Width="75px" > 
         </asp:BoundField> 
         <asp:BoundField DataField="line_code" HeaderText="Line Code" ItemStyle-Width="50px" > 
         </asp:BoundField> 
         <asp:BoundField DataField="BrandName" HeaderText="Brand" 
          ItemStyle-Width="100px" > 
         </asp:BoundField> 
         <asp:BoundField DataField="ProductDescriptionLong" HeaderText="Product" 
          ItemStyle-Width="205px"> 
         </asp:BoundField> 
         <asp:TemplateField HeaderText="Old Qty/Old Price"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%# Bind("ttlqty", "{0:N0}") %>'></asp:Label> 
           <asp:Label ID="Label2" runat="server" Text="/"></asp:Label> 
           <asp:Label ID="Label3" runat="server" Text='<%# Bind("ttlretailprice", "{0:c}") %>'></asp:Label> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ttlqty") %>'></asp:TextBox> 
           <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ttlretailprice") %>'></asp:TextBox> 
          </EditItemTemplate> 
          <ItemStyle Width="70px" /> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="New Qty/New Price"> 
          <ItemTemplate> 
           <asp:Label ID="Label7" runat="server" Text='<%# Bind("new_base_qty", "{0:N0}") %>'></asp:Label> 
           <asp:Label ID="Label8" runat="server" Text="/"></asp:Label> 
           <asp:Label ID="Label9" runat="server" Text='<%# Bind("new_base_retail", "{0:c}") %>'></asp:Label> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("new_base_qty") %>'></asp:TextBox> 
           <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("new_base_retail") %>'></asp:TextBox> 
          </EditItemTemplate> 
          <ItemStyle Width="70px" /> 
         </asp:TemplateField> 
         <asp:BoundField DataField="new_LC" HeaderText="Cost" SortExpression="new_LC" DataFormatString="{0:c}" ItemStyle-Width="50px"/> 
         <asp:BoundField DataField="margin_current" HeaderText="Current Margin" 
          SortExpression="margin_current" ItemStyle-Width="50px" DataFormatString="{0:P1}"/> 
         <asp:BoundField DataField="margin_new" HeaderText="New Margin" 
          SortExpression="margin_new" ItemStyle-Width="50px" DataFormatString="{0:P1}"/> 
         <asp:BoundField DataField="tag_type" HeaderText="Tag Type" 
          ItemStyle-Width="50px" > 
         </asp:BoundField> 
         <asp:BoundField DataField="effective_dt" HeaderText="Effective Date" 
          DataFormatString="{0:MM/dd/yyyy}" ItemStyle-Width="50px" > 
         </asp:BoundField> 
        </Columns> 
       </asp:GridView> 
      </div> 

protected void ChangedUPCs2GridDataBound(object sender, EventArgs e) 
    { 
     ChangedUPCs2.HeaderRow.Attributes["style"] = "display:none"; 
     ChangedUPCs2.UseAccessibleHeader = true; 
     ChangedUPCs2.HeaderRow.TableSection = TableRowSection.TableHeader; 

    } 

答えて

0

これを行うことを可能にする組み込みのASP.NETのためには何もありません、 (Telerikのコントロールのように)それをサポートしている購入ツールの一部。しかし、これを行うことができます。キーは、ユーザーが選択できるようになる可能性のあるすべての並べ替えを構築することです。そして彼らをそれぞれのイベントに結びつける。これは、あなたが持っているのと同じ数のカラムを持つテーブルでは簡単なことではありません。おそらく最も良い方法は個々の要求を処理できるbuild a stored procedureですが、私はそれを簡単なものとして説明しません。ごめんなさい。

+0

ダイナミックSQLの場合は、ストアドプロシージャのアイデアが気に入っています。それは私が予知でそれを構築していた場合私はそれを行う方法です。その後、再びtelerik isnt高価な... – user314321

0

私は助けを願って、あなたが

をしたい、これまで何をして自分のページにその種をいくつかのボタンを追加することができますし、C#のコードを使用すると、アイテムを並べ替えると、GridViewの

を埋めることができます。

関連する問題