2016-09-19 2 views
-1

jQuery UIを使用して、テーブルグリッドをソート可能にすることができます。私の要素はまだ並べ替えられず、エラーも表示されません。私はasp.net mvcでこのメソッドを使用したことはありません。jqueryソート可能な関数が表示されない(mvc)

ご迷惑をおかけして申し訳ありません。

<script type="text/javascript"> 

$('td, th', '#MenuItem').each(function() { 
    var cell = $(this); 
    cell.width(cell.width()); 
}); 

$('#MenuItem tbody').sortable().disableSelection(); 

<table id = "MenuItem" class="promo full-width alternate-rows" style="text-align: center;"> 
      <tr> 
       <th>Prode Code 
       </th> 
       <th>ProdeTemplate 
       </th> 
       <th>Description <!-- JACK EDIT --> 
       </th> 
       <th>Action</th> 
      </tr> 
      <tbody> 
      @foreach (var item in Model.IndexListitem) 
      { 


       <tr> 
        <td class="center-text"> 
         @Html.DisplayFor(modelItem => item.ProductCode) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => item.ProdeTemplate.Description) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => item.Description) 
        </td> 

        <td class="center-text nowrap"> 
         @Html.ActionLink(" ", "Edit", new { id = item.ProdeID }, new { title = "Edit", @class = "anchor-icon-no-text edit" }) 
         @Html.ActionLink(" ", "Details", new { id = item.ProdeID }, new { title = "Details", @class = "anchor-icon-no-text details" }) 
         @Html.ActionLink(" ", "Delete", new { id = item.ProdeID }, new { title = "Delete", @class = "anchor-icon-no-text delete" }) 
        </td> 
       </tr> 

      } 

       </tbody> 

     </table> 
+0

'$( '#1のMenuItem TBODY')を入れてみてくださいdocument.readyブロックに次のコードのブロック全体を置くことであるソート可能()disableSelection();。。' [文書に。準備ができました(https://learn.jquery.com/using-jquery-core/document-ready/) – Knu8

+0

ありがとうございました – user5813072

+0

あなたは私の答えを受け入れてください:) – Knu8

答えて

1

私は@Html and @foreach注釈をあまり慣れていませんよ。しかし、私はこれらの注釈がサーバー側で処理されると思います。したがって、本質的には、まだ生成されていないhtml要素をjqueryで選択しようとしています。

一つの解決策は、

// A $(document).ready() block. 
$(document).ready(function() { 
$('td, th', '#MenuItem').each(function() { 
var cell = $(this); 
cell.width(cell.width()); 
}); 

$('#MenuItem tbody').sortable().disableSelection(); 

}); 
+0

ありがとう私は2番目のブロックを準備関数に入れて働いた。 – user5813072

関連する問題