javascript - jQuery Tablesorter 分页按钮未触发

标签 javascript jquery asp.net-mvc tablesorter

我正在尝试使用 jquery.tablesorter.pager.js 向我的表格控件添加分页。

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>

绑定(bind)代码

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

最佳答案

寻呼机似乎不喜欢我传递的其中一个选项。我仍然不确定哪个是罪魁祸首,但是,它现在可以工作了,因为我传递了一个选项,没有变量:

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

关于javascript - jQuery Tablesorter 分页按钮未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41731034/

相关文章:

javascript - 在我的 jQuery 中,为什么 indexOf 没有从我的数组中找到键?

javascript - Git 远程仓库没有显示在 <ul> 中

javascript - 使用递归函数按顺序进行多个ajax请求,并在所有请求完成后执行回调函数

javascript - Kendo UI 窗口小部件 - 使用模板的动态标题

javascript - 使用 html() 进行 Jquery 导航

asp.net-mvc - 帮忙清理asp.net mvc web.config文件

jquery - ajax 和安全 Controller

javascript - jQuery UI slider - 无法调用未定义的方法 'addClass'

javascript - 在 .html() 被触发后做一些事情

c# - Entity Framework - 使用相同键的多个 1 到 0..1 关系