1

I'm trying to allow for row select on my datatables work (as seen here: http://datatables.net/release-datatables/examples/api/select_single_row.html) but it doesn't seem to work. Any ideas on where I might be going wrong?

I've included the full code here: http://jsfiddle.net/v6VTB/2/

JS

$(document).ready(function () {
    $('#example5').dataTable({
        "bPaginate": true,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": true,
        "bScrollCollapse": true,
        "bInfo": true,
        "bAutoWidth": false
    });
});

var oTable;
var giRedraw = false;

/* Add a click handler to the rows - this could be used as a callback */
$("#example5 tbody").click(function (event) {
    $(oTable.fnSettings().aoData).each(function () {
        $(this.nTr).removeClass('row_selected');
    });
    $(event.target.parentNode).addClass('row_selected');
});

/* Add a click handler for the row */

/* Init the table */
oTable = $('#example5').dataTable();

/* Get the rows which are currently selected */
function fnGetSelected(oTableLocal) {
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();

    for (var i = 0; i < aTrs.length; i++) {
        if ($(aTrs[i]).hasClass('row_selected')) {
            aReturn.push(aTrs[i]);
        }
    }
    return aReturn;
}
1
  • 2
    asking for problems initializing the same plugin twice on the same table especially with different options. Will likely not break but mostly lead to later confusion thinking a set of options should be working but have actually been over written later in code Commented Nov 11, 2012 at 15:45

1 Answer 1

2

the row_selected class is not been defined

see this fiddle http://jsfiddle.net/v6VTB/3/ , added a example css below

.row_selected​{
    color:red;
}​
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.