Why is the whole Web Page refreshing after function call to DataTable
Why is the whole Web Page refreshing after function call to DataTable
I have a Javascript being called as a WebPart on a SharePoint webpage. The script is sourcing data from a SharePoint list and applying the DataTables library functions to format the table nicely. This works nicely when I first open the page and the whole data is sourced from the list and displayed correctly, however when I try to call this function again by a button on the webpage sending in a filter, the filter on the SharePoint list seems to work, the table shown is filtered nicely, however a second or two later the whole webpage is refreshed again and the whole data from the SharePoint is displayed again..
Answers
Without a link to the page showing the issue, it is difficult to say I'm afraid. Perhaps you can show us the function you are calling?
Allan
Hi Allan,
Sorry for the delay, I've found a better solution that fits exactly what I'm trying to do. This is using your example in the following link:
https://datatables.net/examples/plug-ins/range_filtering.html
However I unable to understand what I'm doing wrong. I receiving the below error message in the browser console:
ReferenceError: dataTableClient is not defined
Please see below js code where I've tried to implement your solution:
This is a scoping issue. As you've declared
dataTableClient
within theOnSuccess()
function, it won't be visible within theready()
function. The easiest fix would be to make the variable global,Colin
Hi Colin,
Appreciate your quick response. Unfortunately I'm not a JavaScript programmer, so apologies for the next question if it is a silly question.
I think I've declared it as a global variable by moving line 51 to between lines 15 & 16. I don't get an error message in the console, however the table does not get redrawn/rebuild with the filtering.
Any idea why this may be the case?
Many thanks
IN line 20 you have this:
First its a comment which should be causing syntax errors.
introducerid = min
is an assignment not a comparison. Use either==
or===
for comparisons. More information about the comparison operators can be found here.Kevin
@Lenfant i had the same issue while using search builder buttons. Apparently using datatables via CEWP creates this issue. Solution is to deploy your code on custom aspx pages fully independent of Sharepoint. Hope this resolves your issue. Good luck.
@2008jackson , thanks for your info. Unfortunately I'm not familiar with coding custom aspx pages, still struggling with JavaScript. Do you by any chance have any sample custom aspx pages where DataTables has been used, that I could clone and amend please?
@kthorngren , thank you for your comment.
Hi @Lenfant
The following is a starter template you may use. Create an aspx file with the code below and upload to Site Assets or any document library in SPO.