Large dataset

Large dataset

darrenmarkashdarrenmarkash Posts: 47Questions: 3Answers: 0

Hi
I have a table which is showing the history of what is happening in my application.
It works just fine at the moment but is currently around 80 pages and that's only in development!
Is there a way that instead of using SQL to return all the data (SELECT * FROM history ORDER BY date DESC") I can have the table call for data when the next & previous buttons are used?
I would also need the search function to work which I understand can only search data that is actually loaded onto the page so not sure how this works if all the data is not loaded first?
I think it maybe something that Ajax can do but cant find an example.

Answers

  • darrenmarkashdarrenmarkash Posts: 47Questions: 3Answers: 0
    edited August 2021

    I have made progress by using Ajax which is returning valid JSON (I have checked it using several online utilities) but still getting a message...

    DataTables warning: table id=history_table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    If I run the script by itself in the browser it returns all records as valid JSON.

    If I load the page I need The JSON returns as follows...

    {"draw":1,"recordsTotal":1777,"recordsFiltered":1777,"data":[["","","2021-06-16 15:48:00","Added file: Array",""],["","","2021-06-16 15:48:17","Added file: Array",""],["","","2021-06-21 10:13:58","Added file: Array",""],["001","001","2021-06-16 15:48:32","Deleted file: St Patricks Day Menu.pdf","Darren Ash"],["001","001","2021-06-21 10:15:39","Deleted file: image.jpg","Darren Ash"],["001","n\/a","2021-06-22 14:16:56","Project description saved!","Darren Ash"],["001","n\/a","2021-06-22 14:17:06","Project description saved!","Darren Ash"],["001","n\/a","2021-06-22 14:17:35","Project description saved!","Darren Ash"],["001","n\/a","2021-06-22 14:17:42","Project description saved!","Darren Ash"],["001","001","2021-06-28 11:10:24","Added file: test_open_cv.jpg","Darren Ash"]]}
    
  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    Did you follow the troubleshooting steps presented in the link?
    http://datatables.net/tn/1

    What is the JSON response found in the network inspector when the error occurs?

    Kevin

  • darrenmarkashdarrenmarkash Posts: 47Questions: 3Answers: 0
    edited August 2021

    Hi Kevin

    I realised I was looking at the request and not the response. I had the path to ssp.class.php wrong.

    Seems to be showing data now but I lost the ability to click the rows.

    I had this code before
    <tr class='table-row' data-href='project.php?projNo=$entry->projNo'>

    ... but now I have removed it how do I make the row clickable as above?

    If I use
    $(document).on("click", "tr", function() { window.document.location = $(this).data("href"); });
    that works but I dont have the href anymore so need to get the contents of 2nd column of the clicked row to be able to append to my location.

    Darren

  • darrenmarkashdarrenmarkash Posts: 47Questions: 3Answers: 0

    Got it!

    $(document).on("click", "tr", function() {
      var rowData = table.row( this ).data();
      window.document.location = "project.php?projNo=" + rowData[1];
     });
    
  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    Here is more information about delegated events with Datatables:
    https://datatables.net/examples/advanced_init/events_live.html

    Kevin

Sign In or Register to comment.