jump to spec'd page from JSON

jump to spec'd page from JSON

confundidoconfundido Posts: 15Questions: 5Answers: 0

My server side JSON data source is coming along but the search behavior I'm trying to achieve is this:

1) progressively refine the search adding more letters
2) once it's down to a single result, find the page in the larger results set and then return the page with the UI display the page number in the buttons below and clearing the search box
3) this seems to require both server-side and client-side actions

Is there a way to return a piece of data and call something client-side? And then is there a way to tell the UI we're on a specific page without causing a re-fetch?

Is that the best approach for what I'm trying to do?

Implementation so far:
https://www.freecell.net/f/c/dbscores2.html?game=8x3 (select AS column to sort and type ferc into the search box)

Server-side JSON source (with similar calling params):
http://freecell.net/f/fcv2.p?html=0&game=8x3&column=3&search=ferc

These params find a single match and return a page of regular data but I still need to figure out the pagination and clear the search box.

Worst case I can have it return the single page as it does now but any suggestions about how to play into natural behavior of Datatables would be appreciated.

confundido

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    To check my understanding - as you filter down the table and get to a single result you what to perform some action (in this case showing some other html)?

    Use draw to listen for the table updates and use page.info() inside it to determine how many records are shown. If its 1 then do whatever is needed.

    Allan

  • confundidoconfundido Posts: 15Questions: 5Answers: 0
    edited September 2019

    Is there a cool way for me to pass back some data in the JSON to be interpreted by my draw listener? Like I can add data items in the ajax function, e.g. "game" below:

                data: function ( d ) {
                    d.game = '[varGoesHere]';
                    return JSON.stringify( d );
                }
    

    And thanks for fast response!

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Since the data will change per row, just have the extra data in the row's data object. Then you ca use row().data() to get the row's data in your draw event listener - e.g.:

    table.on('draw', function () {
      if ( table.page.info().recordsDisplay === 1 ) {
        var rowData = table.row(':eq(0)').data();
        // ... do something with it
      }
    });
    

    Allan

This discussion has been closed.