superRaytin / paginationjs

A jQuery plugin to provide simple yet fully customisable pagination.
http://pagination.js.org
MIT License
912 stars 659 forks source link

How to handle exception when there is no 'locator'? #85

Closed xcodeac closed 5 years ago

xcodeac commented 5 years ago

Hi, can you please suggest how to handle exceptions where there is no results / no 'locator' element in the ajax response? Getting the below error:

Uncaught Error: Pagination: dataSource.items is undefined. , as the locator element was 'item' for my case.

Thanks in advance.

kimchuy commented 5 years ago

agree

hiiamninna commented 1 year ago

is this problem solved? I get the same problem, thank you

@kimchuy @xcodeac @superRaytin

superRaytin commented 1 year ago

@hiiamninna Paginationjs doesn't have a way to handle "locator" exceptions, but I think the right way to handle it is to set a correct "locator" value when a "locator" exception occurs, and usually the exception can be immediately discovered at initialization.

superRaytin commented 1 year ago

@hiiamninna I just released 2.6.0 to support catching errors when rendering pagination, below is an example:

$('#demo').pagination({
    dataSource: 'https://yoursite.com/path/to',
    locator: 'items',
    callback: function(data, pagination) {
        // ...
    },
    onError: function(e, errorType) {
        // do something
        // in this case, errorType will be `ajaxSuccessHandlerError`
    },
})

docs: http://pagination.js.org/docs/index.html#onError

hiiamninna commented 1 year ago

Oh, thank you @superRaytin

I have solved it btw, from the backend I initialize the nil locator with empty array and it worked thank you again for your explanation