Ad

Select All Option On Pages With Pagination ASP.NET MVC5 & Jquery

I have an application, where I have a Select All option, which works using JQuery:

    $(".selectall").click(function () {
    $(".individual").prop("checked", $(this).prop("checked"));
});

This works fine on the current page. But I have the page set up so that it loads a partial view using Ajax, so it only loads the table and not the whole view. I then have pagination which also uses a method to skip and take the number of results, you can also display a number of records, the default is 25, but it can go up to 100.

Is there a way that I can get it to select all records, no matter what page I am on, or whether I have chosen to display 10 records, 25 records or 100 records.

I am building the application in ASP.NET MVC5. I would also like some sort of count to display as a heading to say a number of records selected is...

Here is my AJAX:

`@* Pagination Async Partial Handling *@
        $(document).on("click",
            "#indexPager a",
            function() {
                if ($(this).parent().hasClass('disabled') || $(this).parent().hasClass('active'))
                    return false;
                $.ajax({
                    url: $(this).attr("href"),
                    type: 'GET',
                    cache: false,
                    success: function(result) {
                        $('#tableContainer').html(result);
                        addBootstrapTooltips("#tableContainer");
                    }
                });
                return false;
            });
        $(document).on("change",
            "#pageSizeSelector",
            function() {
                var selectedValue = $(this).val();
                $.ajax({
                    url: selectedValue,
                    type: 'GET',
                    cache: false,
                    success: function(result) {
                        $('#tableContainer').html(result);
                        addBootstrapTooltips("#tableContainer");
                    }
                });
            });`

Would anyone be able to give me an indication as to where I could add my JQuery in my AJAX, please?

Ad

Answer

You need to add the below line on your AJAX pagination callback,

$(".individual").prop("checked",$(".selectall").prop("checked"));
Ad
source: stackoverflow.com
Ad