Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 1817

How to get the entire row of all checkbox checked?

$
0
0
I'm using datatables with one column (first one) which includes checkboxes. I need to get all the rows that users checked the checkboxes.
Here is my code

Datatable initialisation:

/* Init the table */
var init = function(){
	var oTable = $("#payed").dataTable({
		 	"sDom" : 'lfrtipL',
		 	"oSelectable" : defaults,
		  	"aoColumns": [
				              {"sTitle" : "Select"},
				              {"sTitle" : "throw"},
				              {"sTitle" : "Type"},
				              {"sTitle" : "Total records"},
				              {"sTitle" : "Date loaded"},
				              {"sTitle" : "payed"}
			             ]
	 		,
			"aoColumnDefs": [
                             
                             { "bSortable": true, "aTargets": [0,1,2,3,4,5] },
                             { "sClass": "readonly", "aTargets": [0,1,2,3,4,5] },
                             { "sClass": "editableCol", "aTargets": [ 0 ] },
                             {	
                            	 "aTargets": [0],    // Column number which needs to be modified
                            	 fnRender: function (o, v) {   // o, v contains the object and value for the column
                            		 		return '<input type="checkbox" id="cellCheckbox" name="cellCheckbox" />';
                             },
                             	"sClass" : 'tableCell'    // Optional - class to be applied to this table cell
                             },
                             {"sWidth": "7%", "aTargets": [0]}
                             
                 
            ],
            "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
				{
					$('td:eq(1)', nRow).html(new Date(aData[1]).customFormat( "#YYYY#-#MM#"));
					$('td:eq(4)', nRow).html(new Date(aData[4]).customFormat( "#YYYY#-#MM#-#DD# #hhh#:#mm#:#ss# "));
					$('td:eq(5)', nRow).html("0");
				}
				if ($('td:eq(0)').is(":checked")){
					$(nRow).addClass('row_selected');
				}
				return nRow;
			},
			"fnCallback": function(json){
				fnCallback(json);
			},
			'bAutoWidth': true,
	    	"bProcessing": false,
	    	"bServerSide": false,
	    	"sAjaxSource": "ddjjCargada/getAllById",
	    	"fnServerData": function ( sSource, aoData, fnCallback ) {
	    		aoData.push( jsonData );
	    		$.getJSON( sSource, jsonData)  
				.done(function(json){
	    			fnCallback(json);
	    		})
				.fail(function(error){
					console.log("Error al cargar "+error);
					alert("Error al cargar los datos del servidor, for favor intentelo mas tarde");
				});
	    	},
	    	'bPaginate': true,
	    	"iDisplayLength": 10,
	    	"bFilter": true,
            "bSort": true,
            "bInfo": true,
            "bJQueryUI" : true,
            "iDisplay":'40000',
            "sPaginationType": "full_numbers"
            
            
        });
	  return oTable;
}

Here is the code that i'm using to get the nodes:

var sendToServer = function(tabla){
	$("#tSend").on('click' , function(){
		
             var rows = $("#talonPago").dataTable().fnGetNodes();
             for(var i=0;i<rows.length;i++)
             {
                var t = cells.push($(rows[i]).find("td:eq(0)").attr(":checked"));
            
             }
        //console.log(cells);
		
	});
}

With the code above I was trying to put the entire row Data from columns that are checked and then send it
to the server.

The problem is that this
    var t = cells.push($(rows[i]).find("td:eq(0)").attr(":checked"));

get all the columns, not just the selected.

Any suggestions?

Viewing all articles
Browse latest Browse all 1817

Trending Articles