pager action checks if data source is a function #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Howdy!
There's a bug report in this pull request, and a bit of a story, so grab a chair...
Background: I'm using react-redux-grid with a
dataSource
which is a custom function that returns a promise. (This lets me add authorization and header details I need for the remote API).I also want my paging type to be
'remote'
also.I believe(d) that this page configuration would work:
and that react-redux-grid would use the
dataSource
I had set up.In fact, what happens is PagerActions
setPageAsync
function'sdataSource
parameter set to{ currentRecords: ..., data: ..., gridType: ...., lastUpdate: ...., proxy: ...., total: ...., treeData: ...}
. What parent components callgridData
.Regardless why this gets passed an object, when it does pass an object, it tries to make an AJAX request to
http://[Object]
. (See https://github.com/bencripps/react-redux-grid/blob/master/src/actions/plugins/pager/PagerActions.js#L105 ). It's trying to serialize thegridData
structure as a string then call that host.But even in this object there's no reference back to my promise (that I could see).
Sooooo I set
PAGER.pagingSource
explicitly to the same function as I use fordataSource
.Which meant that
setPageAsync
'sdataSource
was what I wanted - a function! Except I immediately ran into the same bug as above: trying to send an AJAX request tohttp://[Function]
.SOOOOOOO this patch: check to see if
dataSource
is a function. If it is, use that to get a promise. Else, callRequest.api
as before.There is still a bug here: if you set pagingType to remote, but don't provide a
pagingSource
, why is the data source a record? Don't know - in my use case I'm fine with havingpagingSource
need to be provided / a function (in fact, my code will have to be structured that way for other reasons... likesetPageAsync
not knowing the current sorting of the grid from down in the PagerActions Plain Old Javascript Class. (If there's a way let me know ;) )Let me know if there's anything I can do to get this accepted. Thanks!