row selection example with server-side does nothing?

row selection example with server-side does nothing?

mihomesmihomes Posts: 165Questions: 23Answers: 0
edited May 2014 in DataTables 1.10

Curious as to what the problem here is as the console appears to be showing correct data yet no class is applied to any selected rows nor is the checkmark set.

        "rowCallback": function( row, data, displayIndex ) {
            console.log(data.DT_RowId);
            console.log(row);
            console.log(selected);
            if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
                $(row).addClass('active').find('.checkboxes').attr("checked", true);
            }
        },

console shows the following :

122
<tr id="122" class="odd" role="row">
["122"]

on the flipside if I do the following in the drawcallback instead it works...

            "drawCallback": function() {
                $.each( selected, function ( i, id ) {
                    $('#datatable #'+id).addClass('active').find('.checkboxes').attr("checked", true);
                });
                         },

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    Can you post a link to a test case showing the issue please? I've just tried a simple example and it works as expected: http://live.datatables.net/zasuved/1/edit .

    Allan

  • mihomesmihomes Posts: 165Questions: 23Answers: 0

    I figured out the problem.

    My example does not work because my DT_RowId's are integers. Appending 'ID_' to them and my example works.

    The downside... all processing scripts for the db now need to be edited to reflect that change.

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    An HTML ID can't start with a number - sounds like the browser might be enforcing that constraint!

    Allan

  • mihomesmihomes Posts: 165Questions: 23Answers: 0
    edited May 2014

    New problem... cannot get a class applied to the newly created tr row. Does this have anything to do with being in a callback and/or being a child row?

    "rowCallback": function( row, data ) {
        //create and show new row
        dt.row($(row)).child( format(data), data.DT_RowId+'_child' ).show();
    
        //set selected rows
        if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
            $(row).addClass('active').find('.checkboxes').attr("checked", true);
            $('.'+data.DT_RowId+'_child').parents('tr').addClass('active');
        }               
    }
    
  • mihomesmihomes Posts: 165Questions: 23Answers: 0

    I have no idea why the markdown is not working properly on that code block.

This discussion has been closed.