Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pageResize plugin. Add paging parameter and callback. #359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexDEVpro
Copy link
Contributor

Update pageResize plugin. Add paging parameter to pass it to the draw function call inside pageResize plugin. Add callback which called before draw and provides cancel ability and ability to override the draw paging parameter.

This update became necessary when I started to save the state of the table and decided to reflect the state in URL parameters and load the state from the URL parameters. It was necessary that one user could send a link to another user with a clearly defined list of table rows, taking into account the search string, the number of rows on the page number (despite the screen resolution differences of both users), and the sorting. At the same time, I still needed pageResize, but I had to keep it from being included in the work initially to display the same rows collection as it was sent first or at least I needed to preserve page and not reset it to first page.

@DataTables
Copy link
Collaborator

Could you give me a link to a page showing the issue and it being resolved? I don't quite get it I'm afraid.

@AlexDEVpro
Copy link
Contributor Author

AlexDEVpro commented Dec 28, 2017

Sorry, I can't give a link because it's inside intranet. I'll try to justify the usefulness of this update in more detail.

First of all, with this update it's possible to preserve current page number and not to reset it to the first one when the draw function is called by the pageResize plugin. Now we can choose which paging option the plugin will use by specifying the value of the new parameter pageResizeDrawPagingParameter which passed to the draw function call, i. e. it's the paging parameter of the draw function passed to it's call inside the plugin.

As for the callback pageResizePreDrawCallback. It allows to override the value of the paging parameter per draw function call from the pageResize plugin based on external conditions. It also allows to cancel draw call (by returning false) based on external conditions and/or on the values coming to the callback parameters from pageResize: new page length and old page length. I used this callback to temporary halt the pageResize plugin based on the external condition.

My case is the following.

  1. I use pageResize to automatically calculate the number of rows that fit in a available height space. The user does not move the slider at the bottom of the table to change the number of rows in the table. There is no such slider. But when the user changes the size of the browser window, pageResize automatically increases or decreases the number of rows on the page of the table so that all available height is used. The problem was only that if you scroll through several pages, and then resize the browser window, and thus run the pageResize draw, the page was reset to the first page. With this update, this issue is resolved, because it's possible to pass (through the new plugin parameter pageResizeDrawPagingParameter) a parameter to the draw function call performed inside pageResize plugin.
  2. I use the saving state of the table (stateSave: true). The state of the table is reflected in dynamic URL parameters that are updated in accordance with the table state changes and vice versa - when a link with such parameters is opened then the state of the table is loaded from these parameters. This was necessary so that one user could send another user a link to a strictly defined set of table rows (including page number, page length, search, ordering). The user copies the link and sends it to the second user. The problem is that the second user may have another available height for the table rows and when the second user will open the link, he will see this set of table rows that the first user watched and that he wanted to share with the second by sending a link but only for a moment because pageResize will immediately reset this set if the available height for the second user's table is not the same as for the first user. I needed to prevent this, but I still needed the pageResize plugin. Therefore, I added the ability to halt the redrawing of the table by the pageResize plugin until the second user did not become familiar with the set of rows that the first user shared with him. That's why I added pageResizePreDrawCallback which returns false and thus canceled the change in the number of rows on the page by the pageResize plugin until the second user gets acquainted with the data. At first I thought to make the button "Ok, I looked, now let the table work again as usual, with pageResize" (which, when clicked, changes the result returned by the callback function) for the second user, but I ended up with another solution because the task requirements changes and it was enough not to reset the page number on pageResize table redraw. The new parameter pageResizeDrawPagingParameter is enough for me now. But in my opinion the callback is still makes sense, so I left it for this case.

… function call inside pageResize plugin. Add callback which called before draw and provides cancel ability and ability to override the draw paging parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants