Previous / next editing buttons example COMBINED with search does not work

Previous / next editing buttons example COMBINED with search does not work

bensdbbensdb Posts: 30Questions: 4Answers: 0

https://editor.datatables.net/examples/api/backNext.html

When you do a search to filter out results, surely the ideal functionality would be that the previous / next buttons in the edit modal, would not still use the whole unfiltered table to cycle through?

Would these be relatively easy to implement, or a whole rework of this example?

Replies

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin

    I completely concur! The solution is to use the new API in 1.10 - specifically the rows().nodes() method, and tell the rows() selector to pick only the rows which are in the filter result through the selector-modifier.

    I'll include the updated code in the next Editor release, but for now, this is the updated code:

    Previous button:

    fn: function (e) {
        this.submit( function () {
            var tt = $.fn.dataTable.TableTools.fnGetInstance('example');
            var row = tt.fnGetSelected()[0];
            var rows = table.rows( {filter:'applied'} ).nodes();
            var index = rows.indexOf( row );
    
            tt.fnDeselect( row );
            if ( rows[index-1] ) {
                tt.fnSelect( rows[index-1] );
                $('a.editor_edit').click();
            }
        }, null, null, false );
    }
    

    Next button:

    fn: function (e) {
        this.submit( function () {
            var tt = $.fn.dataTable.TableTools.fnGetInstance('example');
            var row = tt.fnGetSelected()[0];
            var rows = table.rows( {filter:'applied'} ).nodes();
            var index = rows.indexOf( row );
    
            tt.fnDeselect( row );
            if ( rows[ index+1 ] ) {
                tt.fnSelect( rows[index+1] );
                $('a.editor_edit').click();
            }
        }, null, null, false );
    }
    

    Regards,
    Allan

  • bensdbbensdb Posts: 30Questions: 4Answers: 0

    Wow great!!

This discussion has been closed.