2016-09-19 41 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

嘗試把'$( '#菜單項TBODY')排序()disableSelection();'[文檔中。準備](https://learn.jquery.com/using-jquery-core/document-ready/) – Knu8

+0

感謝它的工作 – user5813072

+0

你能接受我的回答:) – Knu8

回答

1

我沒有太多熟悉@Html and @foreach註解。但是,我認爲這些註釋是在服務器端處理的。所以基本上你試圖通過jQuery選擇一些尚未生成的HTML元素。

一種解決方案是把下面的代碼整塊中的document.ready塊

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

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

}); 
+0

謝謝我把第二個塊放入就緒功能,它工作。 – user5813072