absoluteOrderNumber procedurally with the highest number in the table

absoluteOrderNumber procedurally with the highest number in the table

CberubeCberube Posts: 2Questions: 1Answers: 0
    $('#guesses_table').DataTable({
        searching: false,
        paging: false,
        ordering: true,
        info: false,
        ajax: {
            url: 'get_guesses/',
            cache: true
        },
        order: [[0, 'desc']],
        columns: [
          {data: '#'},
          {data: 'title'},
        ],
    });

Description of problem: Hey! I'm trying to get the highest number of column 0 to always be on top, and I'm just blanking out trying to use the absoluteOrder plugin!
I'm sure it's a simple problem to solve, but all I can come up with is storing the highest value when the document is ready, but unfortunately the Table is refreshed procedurally so I need to always stick the row to the top when its column 0 is the highest number.

Any ideas?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    This blog post shows how to initialise a DataTable with that plug-in.

    If you can't get it working, perhaps you can link to the page you are working on so we can take a look at what is going wrong.

    Allan

  • CberubeCberube Posts: 2Questions: 1Answers: 0

    I guess I have read that page but I still don't know how to initialise the plugin with a value I do not know at the time.

    For examples, the AJAX returns a list of dictionaries :

    {'data' : [{'#':0, 'title':' title foo'}, {'#':1, 'title':'xyzz'}, {'#':2, 'title':'title xxx'}]}
    

    Then the user presses a button and then {'#':3, 'title': 'title-xyz'} will be added to the table. It's that row (the one with the column '#' that matches the highest number) that I want to ALWAYS be on top, however the other columns are sorted.

    Hopefully this makes sense!

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Oh I see - sorry. Yes, the plug-in requires the value to be known upfront, so you'd need to make an Ajax call to get the data, determine the number that you want to be fixed and then feed the data into DataTables (which you could do with data).

    Allan

Sign In or Register to comment.