2017-01-18 127 views
4

我試圖使用jquery.tablesorter.pager.js爲我的表控件添加分頁。jQuery Tablesorter分頁按鈕不會觸發

JavaScript文件

/*global my */ 

my.Views.EndingSoon = (function ($) { 
"use strict"; 

var pagerOptions = { 
    container: $("#pager"), 
    output: '{startRow:input} – {endRow}/{totalRows} rows', 
    updateArrows: true, 
    page: 0, 
    size: 10, 
    savePages: true, 
    storageKey: 'tablesorter-pager', 
    pageReset: 0, 
    fixedHeight: true, 
    removeRows: false, 
    countChildRows: false, 
    cssNext: '.next', // next page arrow 
    cssPrev: '.prev', // previous page arrow 
    cssFirst: '.first', // go to first page arrow 
    cssLast: '.last', // go to last page arrow 
    cssGoto: '.gotoPage', // select dropdown to allow choosing a page 
    cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed 
    cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option 
    cssDisabled: 'disabled', // Note there is no period "." in front of this class name 
    cssErrorRow: 'tablesorter-errorRow' // ajax error information row 

}; 

var init = function init() { 
    $("table") 
     .tablesorter({ 
      theme: 'blue', 
      widthFixed: true, 
      widgets: ['zebra', 'filter'] 
     }) 

     .tablesorterPager(pagerOptions); 
} 

return { 
    init: init 
}; 
})(this.jQuery); 

視圖(CSHTML)文件

<table class="tablesorter"> 
    <thead> 
    <tr> 
     <th>Auction Source</th> 
     <th>Short Description</th> 
     <th style="width: 100px">Current Price</th> 
     <th style="width: 125px">Next Required<br />Bid Amount</th> 
     <th>Number of Bids</th> 
     <th>Auction End</th> 
    </tr> 
    </thead> 
    <tbody> 
    @foreach (AuctionItem item in Model.AuctionItems) 
    { 
     <tr> 
      <td>@item.Auction.AuctionSource</td> 
      <td><a target="_blank" href="@item.AuctionItemURL" title="@item.FullDescription">@Truncate(string.IsNullOrEmpty(item.ShortDescription) ? item.FullDescription : item.ShortDescription, 100)</a></td> 
      <td>@item.CurrentPrice.ToString("C")</td> 
      <td>@item.NextBidRequired.ToString("C")</td> 
      <td>@item.NumberOfBids</td> 
      <td>@(item.EndDateTime != DateTime.MinValue ? item.EndDateTime : item.Auction.AuctionEndDate)</td> 
     </tr> 
    } 
    </tbody> 
</table> 
    <div id="pager" class="pager tablesorter-pager"> 
     <img src="@Url.Content("~/Content/Images/first.png")" class="first" /> 
     <img src="@Url.Content("~/Content/Images/prev.png")" class="prev" /> 
     <!-- the "pagedisplay" can be any element, including an input --> 
     <span class="pagedisplay" data-pager-output-filtered="{startRow:input} &ndash; {endRow}/{filteredRows} of {totalRows} total rows"></span> 
     <img src="@Url.Content("~/Content/Images/next.png")" class="next" /> 
     <img src="@Url.Content("~/Content/Images/last.png")" class="last" /> 
    <select class="pagesize"> 
     <option value="10">10</option> 
     <option value="20">20</option> 
     <option value="30">30</option> 
     <option value="40">40</option> 
     <option value="all">All Rows</option> 
    </select> 
    <select class="gotoPage" title="Select page number"> 
    </select> 
</div> 

捆綁代碼

bundles.Add(new ScriptBundle("~/bundles/jquerytablesorter").Include(
        "~/Scripts/jquery.tablesorter.js", 
        "~/Scripts/jquery.tablesorter.combined.js", 
        "~/Scripts/jquery.tablesorter.pager.js")); 

共享_Layout.cshtml片段

@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/jquerytablesorter") 
@Scripts.Render("~/bundles/jqueryval") 
@Scripts.Render("~/bundles/my-js") 
@Scripts.Render("~/bundles/bootstrap") 
</head> 
<body> 

腳本文件夾

Scripts Folder

分頁似乎是「努力」的工作,因爲只有前10行顯示。但是,分頁控件不會觸發任何事件。

如果這會有幫助,我可以推動我的網站的github頁面。

這就是我試圖效仿:https://mottie.github.io/tablesorter/docs/example-pager.html

+0

我不是很熟悉,但我沒有在你有mottie鏈接快速「F12開發工具」的樣子。我注意到他們的例子中,他們沒有像你一樣的

元素。你有沒有嘗試刪除,看看它是否有任何區別?另外,你是否看到控制檯中的任何錯誤? – user961714

+0

是否在jQuery&tablesorter之後加載了'jquery.tablesorter.pager.js'文件? – Mottie

+0

剛剛嘗試刪除表單標籤,沒有運氣那裏。我可以看到,當我調試時,pager.js文件在jQuery和tablesorter之後列出。我還包括我的捆綁邏輯進行審查。感謝你目前的幫助。 – NickHeidke

回答

1

看來,尋呼機不喜歡的我被路過的選項之一,我仍然不知道這是罪魁禍首,但是,它的工作,現在我傳遞一個選項,沒有一個變量:

.tablesorterPager({container: $("#endingSoonPager")}); 
+1

我不確定爲什麼會有問題,但可以在通過更改'$ .tablesorterPager.defaults'中的值來初始化尋呼機之前修改任何默認選項。 – Mottie