Jquery таблица сортировки и разбивки не работает - PullRequest
0 голосов
/ 10 января 2020

Я хочу создать сортируемую таблицу подкачки, как в этом примере.

https://www.aspsnippets.com/Articles/Client-Side-AJAX-based-Paging-and-Sorting-in-ASPNet-MVC.aspx

Однако я получаю jQuery ошибку на chrome .

jquerry error

Я новичок в jQuery, и я не понимаю, что означает ошибка, любая помощь будет оценена.

Вот мой стол

<table id="tblInventoryLocation" class="table table-striped table-bordered dt-responsive nowrap">
    <tr>
        <th><a href="javascript:;">ID</a></th>
        <th><a href="javascript:;">Armario</a></th>
        <th><a href="javascript:;">Cajon</a></th>
        <th></th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td class="InventoryLocationId">
                <span>@item.ubicacion_id</span>
                <input type="text" value="@item.ubicacion_id" style="display:none" />
            </td>
            <td class="Closet">
                <span>@item.armario</span>
                <input type="text" value="@item.armario" style="display:none" />
            </td>
            <td class="Drawer">
                <span>@item.cajon</span>
                <input type="text" value="@item.cajon" style="display:none" />
            </td>
            <td>
                @*@Html.ActionLink("Edit", "Edit", new { id = item.ubicacion_id })*@
                <a class="Edit" href="javascript:;">Edit</a>
                <a class="Update" href="javascript:;" style="display:none">Update</a>
                <a class="Cancel" href="javascript:;" style="display:none">Cancel</a>
                <a class="Delete" href="javascript:;">Delete</a>
                @*@Html.ActionLink("Details", "Detail", new { id = item.ubicacion_id }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.ubicacion_id },
                                    new { onclick = "return confirm('¿Estás seguro de que deseas eliminar este artículo?');" })*@
            </td>
        </tr>
    }
    <tr>
</table>

А вот мой jQuery код:

<script type="text/javascript" src="~/Scripts/jquery1.8.3.min.js"></script>
<script src="~/Scripts/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
    var sortName = "";
    var sortDirection = "ASC";
    $(function () {
        GetCustomers(1);
    });
    $("body").on("click", "#tblInventoryLocation th a", function () {
        sortName = $(this).html();
        sortDirection = sortDirection == "ASC" ? "DESC" : "ASC";
        GetCustomers(1);
    });
    $("body").on("click", ".Pager .page", function () {
        GetCustomers(parseInt($(this).attr('page')));
    });
    function GetCustomers(pageIndex) {
        $.ajax({
            type: "POST",
            url: "/InventoryLocation/AjaxMethod",
            data: '{pageIndex: ' + pageIndex + ', sortName: "' + sortName + '", sortDirection: "' + sortDirection + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
        });
    };
    function OnSuccess(response) {
        var model = response;
        var row = $("#tblInventoryLocation tr:last-child").removeAttr("style").clone(true);
        $("#tblInventoryLocation tr").not($("#tblInventoryLocation tr:first-child")).remove();
        $.each(model.Customers, function () {
            var customer = this;
            $("td", row).eq(0).html(customer.ubicacion_id);
            $("td", row).eq(1).html(customer.armario);
            $("td", row).eq(2).html(customer.cajon);
            $("#tblInventoryLocation").append(row);
            row = $("#tblInventoryLocation tr:last-child").clone(true);
        });
        $(".Pager").ASPSnippets_Pager({
            ActiveCssClass: "current",
            PagerCssClass: "pager",
            PageIndex: model.PageIndex,
            PageSize: model.PageSize,
            RecordCount: model.RecordCount
        });
    };
</script>

Это код для ASPSnippets_Pager.min. js

function ASPSnippetsPager(a, b) { var c = '<a style = "cursor:pointer" class="page" page = "{1}">{0}</a>'; var d = "<span>{0}</span>"; var e, f, g; var g = 5; var h = Math.ceil(b.RecordCount / b.PageSize); if (b.PageIndex > h) { b.PageIndex = h } var i = ""; if (h > 1) { f = h > g ? g : h; e = b.PageIndex > 1 && b.PageIndex + g - 1 < g ? b.PageIndex : 1; if (b.PageIndex > g % 2) { if (b.PageIndex == 2) f = 5; else f = b.PageIndex + 2 } else { f = g - b.PageIndex + 1 } if (f - (g - 1) > e) { e = f - (g - 1) } if (f > h) { f = h; e = f - g + 1 > 0 ? f - g + 1 : 1 } var j = (b.PageIndex - 1) * b.PageSize + 1; var k = j + b.PageSize - 1; if (k > b.RecordCount) { k = b.RecordCount } i = "<b>Records " + (j == 0 ? 1 : j) + " - " + k + " of " + b.RecordCount + "</b> "; if (b.PageIndex > 1) { i += c.replace("{0}", "<<").replace("{1}", "1"); i += c.replace("{0}", "<").replace("{1}", b.PageIndex - 1) } for (var l = e; l <= f; l++) { if (l == b.PageIndex) { i += d.replace("{0}", l) } else { i += c.replace("{0}", l).replace("{1}", l) } } if (b.PageIndex < h) { i += c.replace("{0}", ">").replace("{1}", b.PageIndex + 1); i += c.replace("{0}", ">>").replace("{1}", h) } } a.html(i); try { a[0].disabled = false } catch (m) { } } (function (a) { a.fn.ASPSnippets_Pager = function (b) { var c = {}; var b = a.extend(c, b); return this.each(function () { ASPSnippetsPager(a(this), b) }) } })(jQuery);

ОБНОВЛЕНИЕ

Я узнал, что благодаря Libern-M я вызывал одни и те же сценарии несколько раз. Вот моя новая javascript ошибка.

new error

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...