The problem is that the defaultOption searchPanes object is overwritten by the searchPanes.preSelect option. I think you will need to add true as the first parameter in $.extend(). See the jQuery extend() docs for details about deep copying.
no problem @kthorngren suggestion actually took care of my issue. Thanks!
I did run into anther issue now that I have upgraded to latest datatable (2.0.2) when I set the displayStart with the searchPane.preSelect in the url, it is not working. https://live.datatables.net/kexidave/1/edit
this was working for me on the previous version of datatable (dt-1.13.8) where I was changing the values for displayStart on the url and it would pick the right pagination.
Looks like the problem happens when searchPanes performs the searches. When it calls draw its reseting back to the first page. Presumably SearchPanes 2.3.0 calls draw() without passing the false parameter to stay on the same page when preselecting. I added these events to both examples to see this:
$(document).on('select.dt', function () {
console.log('select');
});
$('#example').on('draw.dt', function () {
console.log('draw');
})
$('#example').on('draw.dt', function () {
console.log('page', $('#example').DataTable().page.info().page);
})
Thanks! @kthorngren. this isn't really related to my original question but the reason I wanted to upgrade for DT 2.0.2 was because it had the fix for the showing message issue ex. Showing 31 to 26 of 26 programs (filtered from 208 total entries). would there be a way to address that issue without upgrading to DT 2.0.2
As far as I know there is not a way to know when searchPanes has completed its search. I seems to occur after initComplete.
Code would need to be added to see if displayStart was passed as a parameter and to calculate the page. Use page.info() to get the page length to calculate the page number. Use page() to set the page. It looks like setting the page() to a non-existent page results in landing on page 1.
Thanks @kthorngren I tried playing around with initComplete it really isn't working for me as I want the selected paging to remain when I change around the filters in the searchPane.
Based on the fix in SearchPanes 2.3.0 each SearchPanes search will go back to the first page. I don't think there is an easy work around for staying on the current page anytime SearchPanes is used.
@kthorngren actually I think you were right! It could have been the searchPane older version that was causing the bug in the thread. so I was just playing around with using DT version 1 with searchPane 2.3.0 since the release note for the searchPane 2.3.0 states it should be compatible with DT 1 .
I have these versions so far
and am getting this error right now tho, Uncaught TypeError: Cannot read properties of undefined (reading 'apply')
I don't think searchPane 2.3.0 is compatible with DataTables 1 even though the release note states that. kept getting "Loading Search Panes" message. as soon as i switch to 2.2.0 the issue goes away
Sorry about that - there is indeed a compatibility issue with DT1. Because DT1 isn't supported any more, I don't have the unit tests running on it, I just check by hand. And I missed that one. Apologies.
I've committed a fix that should do the job. I'm not at my standard computer atm, so I can't do a full check, but I'll check in the morning that the nightly build carries the change.
Moreover, there does appear to be an underlying issue in SearchPanes when using preSelect. I don't know what is causing that I'm afraid. If a workaround such as what Kevin suggests does the trick, go with that for now. SearchPanes needs a bit of a reworking.
One thing - Kevin asked me if there was a way to know when a SearchPane is triggered a search on the main table. Somewhat surprisingly, there isn't I'm afraid. There should really be an event for that.
For the moment, you'd need to treat all search actions on the host table as potentially coming from SearchPanes or any other source.
Doh - sorry. Just committed this change which should fix that. The nightly will take about 10 minutes before it is up to date, and you might want to change the ? query parameter.
Thanks @allan, it's working for me now. However, I haven't found a workaround for using displayStart while maintaining the current page position as SearchPanes is being used.. For the time being, so I am gonna stick to SearchPane 2.2.0 and hope to upgrade in the future.
Reviving this thread to check to see if it has been addressed or would it be addressed in the near future? The problem concerns the combination of searchPanes.preSelect and displayStart, which causes the display to reset to the first page in searchPane version 2.3.0.
Sorry that is not something that I've worked on yet. It is in my backlog. I rather suspect this will continue to be present until I can work on a rewrite of SearchPanes (which it is due for).
Replies
The problem is that the defaultOption
searchPanes
object is overwritten by thesearchPanes.preSelect
option. I think you will need to addtrue
as the first parameter in$.extend()
. See the jQuery extend() docs for details about deep copying.Kevin
Sorry, I've not had a chance to look into this yet. It will likely involve encoding a search using array syntax, but it isn't something I've done yet.
Sorry, I'm swamped with support requests at the moment and I'm not managing to keep up.
Allan
no problem @kthorngren suggestion actually took care of my issue. Thanks!
I did run into anther issue now that I have upgraded to latest datatable (2.0.2) when I set the displayStart with the searchPane.preSelect in the url, it is not working.
https://live.datatables.net/kexidave/1/edit
url:
https://live.datatables.net/kexidave/1?searchPanes.preSelect=%5B%7B%22rows%22%3A%5B%22Edinburgh%22%2C%22London%22%5D%2C%22column%22%3A2%7D%5D&displayStart=20
this was working for me on the previous version of datatable (dt-1.13.8) where I was changing the values for displayStart on the url and it would pick the right pagination.
https://live.datatables.net/hazijoxu/1/edit
https://live.datatables.net/hazijoxu/1?searchPanes.preSelect=%5B%7B%22rows%22%3A%5B%22Edinburgh%22%2C%22London%22%5D%2C%22column%22%3A2%7D%5D&displayStart=20
Looks like the problem happens when searchPanes performs the searches. When it calls draw its reseting back to the first page. Presumably SearchPanes 2.3.0 calls
draw()
without passing thefalse
parameter to stay on the same page when preselecting. I added these events to both examples to see this:DT 2.0.2 output:
https://live.datatables.net/nenozalo/1?searchPanes.preSelect=%5B%7B%22rows%22%3A%5B%22Edinburgh%22%2C%22London%22%5D%2C%22column%22%3A2%7D%5D&displayStart=20
Where the DT vers 1 has this output:
It stays on page 2 after calling draw.
https://live.datatables.net/habanozu/1?searchPanes.preSelect=%5B%7B%22rows%22%3A%5B%22Edinburgh%22%2C%22London%22%5D%2C%22column%22%3A2%7D%5D&displayStart=20
@allan will need to take a look.
Kevin
Thanks! @kthorngren. this isn't really related to my original question but the reason I wanted to upgrade for DT 2.0.2 was because it had the fix for the showing message issue ex. Showing 31 to 26 of 26 programs (filtered from 208 total entries). would there be a way to address that issue without upgrading to DT 2.0.2
I'm not familiar with the issue. Was it discussed in this or another thread?
Maybe open a new thread with this issue.
Kevin
yes it was discussed here: https://datatables.net/forums/discussion/77999
revising this @allan I noticed the latest release 2.0.3 didn't not have a fix for this, you have any workaround or suggestion for this?
I believe issue with
searchPanes.preSelect
resetting to the first page is due to this fix in SearchPanes 2.3.0:See the release notes. I believe this is the fix you are referencing in this thread:
https://datatables.net/forums/discussion/77999
Here is a simplified example:
https://live.datatables.net/salupuke/1/edit
I don't know of a workaround for this. @allan will need to decide how to handle the combo of
searchPanes.preSelect
anddisplayStart
.Kevin
One workaround, which I don't think is a good one, is to use setTimeout() in
initComplete
to set the paging. For example:https://live.datatables.net/qimipaho/1/edit
As far as I know there is not a way to know when searchPanes has completed its search. I seems to occur after
initComplete
.Code would need to be added to see if
displayStart
was passed as a parameter and to calculate the page. Usepage.info()
to get the page length to calculate the page number. Usepage()
to set the page. It looks like setting thepage()
to a non-existent page results in landing on page 1.Kevin
Thanks @kthorngren I tried playing around with initComplete it really isn't working for me as I want the selected paging to remain when I change around the filters in the searchPane.
Based on the fix in SearchPanes 2.3.0 each SearchPanes search will go back to the first page. I don't think there is an easy work around for staying on the current page anytime SearchPanes is used.
Kevin
what is the oldest version of SearchPane that I can use with DT 2.0. I am thinking maybe downgrading might help?
I believe 2.3.0 is the first release compatible with 2.0. If you use a previous version you might rin into the issue in this thread you linked to.
Kevin
hmm for the thread I linked is related to a bug in DT version 1, and which @allen responded saying it was addressed in DT 2.0.
@kthorngren actually I think you were right! It could have been the searchPane older version that was causing the bug in the thread. so I was just playing around with using DT version 1 with searchPane 2.3.0 since the release note for the searchPane 2.3.0 states it should be compatible with DT 1 .
I have these versions so far
and am getting this error right now tho, Uncaught TypeError: Cannot read properties of undefined (reading 'apply')
I don't think searchPane 2.3.0 is compatible with DataTables 1 even though the release note states that. kept getting "Loading Search Panes" message. as soon as i switch to 2.2.0 the issue goes away
https://live.datatables.net/covikiwa/1/edit
Sorry about that - there is indeed a compatibility issue with DT1. Because DT1 isn't supported any more, I don't have the unit tests running on it, I just check by hand. And I missed that one. Apologies.
I've committed a fix that should do the job. I'm not at my standard computer atm, so I can't do a full check, but I'll check in the morning that the nightly build carries the change.
Moreover, there does appear to be an underlying issue in SearchPanes when using
preSelect
. I don't know what is causing that I'm afraid. If a workaround such as what Kevin suggests does the trick, go with that for now. SearchPanes needs a bit of a reworking.Allan
One thing - Kevin asked me if there was a way to know when a SearchPane is triggered a search on the main table. Somewhat surprisingly, there isn't I'm afraid. There should really be an event for that.
For the moment, you'd need to treat all search actions on the host table as potentially coming from SearchPanes or any other source.
Allan
Thanks Allen! I am trying to fix the issue on my production app, so really appreciate Kevin's and yours support on this
Hi, when do I get to use the new fix? can I test it using this link
https://nightly.datatables.net/js/dataTables.min.js
The change was in SearchPanes, so https://nightly.datatables.net/searchpanes/js/dataTables.searchPanes.js?2024-03-26 is the file that would carry it. I've added a query parameter just to make sure you get the latest version.
Allan
hmm I am still getting the same error:
https://live.datatables.net/hudajonu/1/edit
Doh - sorry. Just committed this change which should fix that. The nightly will take about 10 minutes before it is up to date, and you might want to change the
?
query parameter.Allan
thanks @allan. sorry still not working for me for some reason. i don't get the error message but the searchPane is not displayed
the version i am using are - 1.13.11 for datatable, 2.3.0( nightly build ) for searchPane, i picked select 1.7.0 and button 2.4.0
https://live.datatables.net/fijibija/1/edit
Third time is the charm: https://live.datatables.net/fijibija/2/edit . Sorry - apparently I made more DT2 specific changes that I remembered.
Allan
Thanks @allan, it's working for me now. However, I haven't found a workaround for using displayStart while maintaining the current page position as SearchPanes is being used.. For the time being, so I am gonna stick to SearchPane 2.2.0 and hope to upgrade in the future.
Reviving this thread to check to see if it has been addressed or would it be addressed in the near future? The problem concerns the combination of searchPanes.preSelect and displayStart, which causes the display to reset to the first page in searchPane version 2.3.0.
Sorry that is not something that I've worked on yet. It is in my backlog. I rather suspect this will continue to be present until I can work on a rewrite of SearchPanes (which it is due for).
Allan
@allan thanks. I will keep checking then