How to make current row visible?

How to make current row visible?

marcuswmarcusw Posts: 3Questions: 1Answers: 0
edited November 2015 in Free community support

hi

My 1st Datatable shows employees. The name column is sorted. After changing a name from "Anna" to "Zappel" it's not visible in the datatable anymore. How can I make this row visible using JavaScript? My table doesn't use paging. It uses scrolling (scrollY=300px). Only ~10 rows are visible. Here's a piece of my JavaScript code:

        $.post("/rest/" + gridId + "/apply", data, function(json) {
            if (json.status == "ok") {
                var tbl = $("#" + gridId).DataTable();
                var id = json.object.id;
                tbl.data().each(function(value, index) {
                    if (value[value.length - 1] == id) { // the last column contains the non-visible id
                        tbl.row(index).data(json.row).draw();
// problem: after that it's possible that this row is not visible any more
                    }
                });
            } else {
                console.error("apply response on client: Error status: " + json.status);
            }
        }, "json");

Regards,

Marcus

(JS newbie, DataTables 1.10.9, Windows 7, Firefox 42.0, Java 8, Eclipse Mars.1)

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Well think about this... You said you had it sorted by name.. then you change it from "Anna" to "Zappel"... of course its going to zip down to the bottom..

    This ones really more of a logic issue than anything, honestly.

    If you dont want the order to change after the value is changed, you can set the order to an empty array - [], that will disable ordering by default.

    Alternatively, you could get scroll to where the row got re-located at. Just use the row().scrollTo()

  • marcuswmarcusw Posts: 3Questions: 1Answers: 0

    I look for something like row(index).scrollTo().
    Okay, I added the Scroller extension. But it does not work with pagination=off.

  • marcuswmarcusw Posts: 3Questions: 1Answers: 0

    Now I use

                            tbl.row(index).data(json.row).draw('page');
    

    This does not change ordering (until the user presses the column header). That's not the best solution, but better than before.

This discussion has been closed.