How to know if a row is selected
How to know if a row is selected
DiegoTc
Posts: 10Questions: 0Answers: 0
Hi
I will like to know if I have a selected row
This is my code
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "tomacorrienteslist.jsp",
"bFilter": false,
"bSort": false,
"bInfo": true,
"bPaginate": false,
"aaSorting": [[ 4, "desc" ]],
"aoColumns": [
{ "mData": "codigo" },
{ "mData": "descripcion" },
{ "mData": "xbee_id" }
],
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single",
"aButtons": [ ]
}
} );
} );
Agregar
Codigo
Descripcion
XBee
[/code]
This is my code when I want to click on the button
[code]
$( "#agregar" )
.button()
.click(function() {
if(IS THERE A FUNCTION TO KNOW IF I HAD A SELECTED ROW)
$( "#crear_data" ).modal( 'show' );
});
[/code]
I will like to know if I have a selected row
This is my code
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "tomacorrienteslist.jsp",
"bFilter": false,
"bSort": false,
"bInfo": true,
"bPaginate": false,
"aaSorting": [[ 4, "desc" ]],
"aoColumns": [
{ "mData": "codigo" },
{ "mData": "descripcion" },
{ "mData": "xbee_id" }
],
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single",
"aButtons": [ ]
}
} );
} );
Agregar
Codigo
Descripcion
XBee
[/code]
This is my code when I want to click on the button
[code]
$( "#agregar" )
.button()
.click(function() {
if(IS THERE A FUNCTION TO KNOW IF I HAD A SELECTED ROW)
$( "#crear_data" ).modal( 'show' );
});
[/code]
This discussion has been closed.
Replies
http://www.datatables.net/extras/tabletools/api and you'll want fnGetSelected
Uncaught TypeError: Cannot call method 'fnIsSelected' of null
[code]
var oTT = TableTools.fnGetInstance( 'example' );
if ( oTT.fnIsSelected( $('#example tbody tr:eq(0)')[0] ) ) {
alert( 'First row is selected' );
} else {
alert( 'First row is not selected' );
}
[/code]
Any idea why?
If someone has the same issue I live the source code
[code]
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "tomacorrienteslist.jsp",
"bFilter": false,
"bSort": false,
"bInfo": true,
"bPaginate": false,
"sDom": '<"clear">lfrTt',
"aaSorting": [[ 4, "desc" ]],
"aoColumns": [
{ "mData": "codigo" },
{ "mData": "descripcion" },
{ "mData": "xbee_id" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [ ]
}
} );
$( "#editar" )
.button()
.click(function() {
oTT = TableTools.fnGetInstance( 'example' );
var filas=oTT.fnGetSelectedData();
if(filas.length == 0){
alert( 'First row is not selected' );
}
else{
alert( 'First row is selected' );
$( "#editar_data" ).modal( 'show' );
}
[/code]