Getting Selected row/rows Data
Getting Selected row/rows Data
kfirr
Posts: 10Questions: 2Answers: 0
Hi everyone,
I'm trying to pass the row data to php function that insert the rows into DB but i'm getting all off the table data
and not row that i select.
My code:
$(document).ready( function () {
var table = $('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"language": {
"info": "<strong>Showing _START_ to _END_ of _TOTAL_ Alerts.</strong>"
},
"processing": true,
"sAjaxSource": "<?php echo base_url() .'index.php/welcome/main_data';?>",
"oTableTools": {
"sRowSelect": "single",
"sSwfPath": "media/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "ajax",
"bSelectedOnly": "true",
"sAjaxUrl" : "<?php echo base_url();?>index.php/welcome/insert",
"sButtonText": "Add To Alexandria",
"fnClick": function( nButton, oConfig ) {
var sData = this.fnGetTableData(oConfig);
$.ajax( {
"url": oConfig.sAjaxUrl,
"data": [
{ "name": "tableData", "value": sData }
],
"success": oConfig.fnAjaxComplete,
"dataType": "json",
"type": "POST",
"cache": false,
"error": function () {
alert( "Error detected when sending table data to server" );
}
} );
}
},
{
"sExtends": "copy",
"sButtonText": "Copy",
"oSelectorOpts": { filter: 'applied',page: 'current'},
},
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
}
} );
$('#example tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
} );
} );
someone could help me please?
best regards!
This discussion has been closed.
Answers
by the way, how i can post the code so it can be readable for you?
put 3 ``` before and after your code dump
Thanks Modgility, i have edited my question,
any ideas about the question's solution?
You're welcome :)
Unfortunately, I've never tried to do what you're doing so I feel like I'm not really qualified to give you an answer. But I'll take a guess?
It seems like you're value is sData, and the value of sData is set to be this.fnGetTableData(oConfig). Is this variable set to get all of your table's data at once? Maybe there is a way to set that data as only a specific piece of a row that you click on? Again, I'm not really sure but this is only my guess.
Good luck!
Yeah you right but i also add
"bSelectedOnly": "true",
so i guess it should get only the selected rows, There must be someone that
had the same issue. anyway thanks for the quick comment!
so i succeeded getting only the selected row/rows but the ajax
still sending error message about the sending data.
my currently code:
my php function on the server side is only printing content of data to file:
Please help me
hi everyone ,
so i figured out how to do it and now it works, im getting the selected rows
data into my server side php function.
i thought to share the code with you guys
the only problem is that even if i'm getting the data to the server side,
the error alert is keep showing up - there is a way to fix it?