joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

Auto-Hide Pagination for only One Page of Results #76

Open argentini opened 7 years ago

argentini commented 7 years ago

It would be great to have an option to auto-hide the pagination and stats when there's only one page of results. In the mean time, I wrote a JavaScript solution:

STEP 1. In your grid config, add this option:

.WithClientSideLoadingCompleteFunctionName("mvcGridHidePagination")

STEP 2. Add this JavaScript function (and JQuery) to your page:

function mvcGridHidePagination() {

    $("div[id^='MVCGridTableHolder_'] ul.pagination").each(function (index) {

        if ($(this).children().length == 3) {

            $(this).parent().parent(".row").hide();
        }
    });
}

$(document).ready(function() {

    mvcGridHidePagination();
});

This selector chooses all instances of the pagination list that only have three children (Prev, Next, and 1) and then navigates up two parents to the parent div with class ".row" and hides it. You have to run it on document load to hide them on page load. The MVCGrid event handles re-hiding if you sort, filter, etc. each grid.

Hope this helps someone else!

joeharrison714 commented 7 years ago

@argentini thanks for posting this!

argentini commented 7 years ago

No problem. I'm using it on my company's tools site... https://tools.fynydd.com/TechTrends and it's been working well. Thanks for a great tool!