Fork me on GitHub

Javascript API

Javascript API is new feature added in MvcPager 3.0, using Javascript API, you can iterate all MvcPagers on the current page, get property values and jump to specified page.
Note: In order to use Javascript API, you must add jQuery library and register MvcPager jQuery plugin using Html.RegisterMvcPagerScriptResource() method.

Webdiyer.MvcPagers is a global array object that contains all the MvcPagers on the current page, each MvcPager is an javascript object of type Webdiyer.MvcPager, you can get a specified MvcPager by its index or use getById(id) method which get a specified MvcPager by its client id attribute, see the examples bellow:

Get MvcPager by index:

var pager = Webdiyer.MvcPagers[0];

Get MvcPager by id:

var pager = Webdiyer.MvcPagers.getById("mypager");

Webdiyer.MvcPager has following properties:

NameDescription
currentPageIndexCurrent page index.
pageCountTotal number of pages.
idCliend DOM Id, maps to the PagerOptions.Id property.
isAjaxPagerWhether the MvcPager is an AjaxPager.
invalidPageErrMsgThe error message to be displayed when page index is invalid (not a valid integer), maps to the PagerOptions.InvalidPageIndexErrorMessage property.
outOfRangeErrMsgThe error message to be displayed when page index is oute of range, maps to the PagerOptions.PageIndexOutOfRangeErrorMessage property.
firstPageUrlThe url of the first page.
pageIndexNameThe page index parameter name in the current route, maps to the PagerOptions.PageIndexParameterName property.
pageIndexBoxThe id of the page index box prefixed with "#", maps to the PagerOptions.PageIndexBoxId property.
goToButtonThe id of the go-to-page button prefixed with "#", maps to the PagerOptions.GoToButtonId property.
maxPageIndexItemsThe maximum number of page indices to be displayed within page index dropdownlist, maps to the PagerOptions.MaximumPageIndexItems property.

Webdiyer.MvcPager has goToPage(pageIndex) method that can be used to jump to the specified page, this method performs validation of the page index that passed as parameter beform jumping to that page.

Live demo:


Go to page: