i have a server side datatable with a checkbox as last column.
in this when i check a checkbox and goes to another page or i search som value and returns the checking disappers.
how to make this checkbox remains checked
iam using php and my view part is
<table class="table table-striped table-bordered bootstrap-datatable datatable" path="result/mark-list-json/<?php echo $selected_exam; ?>/" id="servertable123"><!--table starts-->
<thead>
<tr>
<th width="5%">Sl</th>
<th width="7%">Reg No</th>
<th width="7%">Name</th>
<th width="10%">School</th>
<th width="10%">Mark</th>
<th width="5%">Rank</th>
<th width="5%">Publish</th>
</tr>
</thead>
</table>
and model function
function mark_list_json($exam_name = '') {
$exam_code = '';
if($exam_name!=''){
$examcde= $this->db->fetch_object($this->db->query("SELECT exam_code FROM exam WHERE exam_id=$exam_name"));
foreach($examcde as $examcde){
$exam_code = $examcde->exam_code;
}}
$exam_name=$this->db->escape($exam_name);
$aColumns = array("sl", "student_rollno", "student_name" ,"student_school","mark_mark","student_rank","student_publish");
$aQuery = "student_id as sl,student_rollno, student_name, student_school,mark_mark,(CASE mark_remarks WHEN '0' THEN ( FIND_IN_SET( mark_mark, (SELECT GROUP_CONCAT( mark_mark ORDER BY mark_mark DESC )FROM mark JOIN student ON student_id=mark_student WHERE student_status=1 AND student_exam= $exam_name )) ) WHEN 'Absent' THEN 'Absent' WHEN 'Result Pending' THEN 'Result Pending' ELSE '' END) as student_rank,student_publish";
$sIndexColumn = "student_id";
$sTable = "student JOIN class ON student_class=class_id JOIN mark ON mark_student=student_id";
$sLimit = "";
$iDisplayStart = isset($_GET['iDisplayStart']) ? $_GET['iDisplayStart'] : 0;
$iDisplayLength = isset($_GET['iDisplayLength']) ? $_GET['iDisplayLength'] : 0;
if (isset($_GET['iDisplayStart']) && $iDisplayLength != '-1') {
$sLimit = " LIMIT " . $this->db->escape($iDisplayStart) . ", " . $this->db->escape($iDisplayLength);
}
$sOrder = " ";
if (isset($_GET['iSortCol_0']) && $_GET['iSortCol_0'] == 0 && $_GET['iSortingCols'] == 1)
$sOrder = " ORDER BY mark_mark DESC";
else if (isset($_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i = 0; $i < intval($_GET['iSortingCols']); $i++)
if ($_GET['bSortable_' . intval($_GET['iSortCol_' . $i])] == "true")
$sOrder .= $aColumns[intval($_GET['iSortCol_' . $i])] . ($_GET['sSortDir_' . $i] === 'asc' ? ' asc' : ' desc') . ", ";
$sOrder = substr_replace($sOrder, "", -2);
if ($sOrder == "ORDER BY")
$sOrder = "";
}
$sSearch = isset($_GET['sSearch']) ? $_GET['sSearch'] : "";
if($exam_name!=''){
$sWhere = "WHERE student_status=1 AND student_exam=$exam_name ";
}else{
$sWhere = "WHERE student_status=1 AND student_exam=0 ";
}
if ($sSearch != "") {
$sWhere = "WHERE (";
for ($i = 0; $i < count($aColumns); $i++) {
if ($i == 1 || $i == 2) {
$sWhere .= $aColumns[$i] . " LIKE '%" . $_GET['sSearch'] . "%' OR ";
}
}
$sWhere = substr_replace($sWhere, "", -3);
$sWhere .= ')';
}
$sQuery = " SELECT SQL_CALC_FOUND_ROWS $aQuery FROM $sTable $sWhere $sOrder $sLimit ";
$rResult = $this->db->query($sQuery);
$iResult = $this->db->query('select FOUND_ROWS() AS found_rows');
$iFilteredTotal = $this->db->row($iResult)->found_rows;
$sQuery = " SELECT $sIndexColumn FROM $sTable ";
$aResultTotal = $this->db->query($sQuery);
$iTotal = $this->db->num_rows($aResultTotal);
$sEcho = isset($_GET['sEcho']) ? $_GET['sEcho'] : "";
$output = array(
"dt_params" => "doprint_html('result/print_mark_list/".$exam_name."/?".$_SERVER['QUERY_STRING']."')",
"sEcho" => intval($sEcho),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
$sl_count = $iDisplayStart + 1;
foreach ($this->db->fetch_object($rResult) as $aRow) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
if ($aColumns[$i] == 'sl') {
$row[] = $sl_count;
}
else if ($aColumns[$i] == 'student_rollno') {
$row[] = $exam_code.$aRow->$aColumns[$i];
}
else if ($aColumns[$i] == 'student_publish') {
if($aRow->$aColumns[$i]==1){
$checked='checked' ;
$sl=1;
}else{
$checked='' ;
$sl='';
}
$row[] ='<input type="checkbox" name="checkAll[]" value="'.$sl.'" id="checkAll"'.$checked.'>
<input type="hidden" name="std_ids[]" value="'.$aRow->sl.'" id="std_ids">';
}else {
$row[] = $aRow->$aColumns[$i];
}
}
$output['aaData'][] = $row;
$sl_count++;
}
return json_encode($output);
}
and the script is
datatable_server12('#servertable123');
function datatable_server12(id,column){
var base_url = $("meta[name=baseurl]").attr("content");
var tStatus = false;
if($("#tools").length) {
var tools = $("#tools").html();
tStatus = true;
}
if ($(id).length) {
var rowCount = ($(id + ' tr th').length);
var mColumns = [];
var new_rowCount = rowCount;
if(tStatus) {
new_rowCount = rowCount - 1;
}
for(var i = 0; i < new_rowCount; i++){
mColumns.push(i) ;
}
$.fn.dataTableExt.sErrMode = 'throw';
var oTable = $(id).dataTable({
// "sDom": "<'row-fluid'<'span9'<'input-tools'>><'span3'<'export-btn'T>>><'row-fluid'<'span12't>>",
"sDom": "<'row-fluid'<'span3 pull-left'l><'span3 pull-right'f>>t<'export-btn'T<'span6 pull-right'p>><'row-fluid' <'span12 pull-right'i>>",
"bProcessing": false,
"bServerSide": true,
"sServerMethod": "GET",
"sAjaxSource": base_url + $(id).attr("path"),
"oTableTools": {
"sSwfPath": "assets/lib/datatables/media/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "text",
"sButtonText": "Export to Excel",
// 'mColumns':mColumns
fnComplete:function(e){
var valid = true;
var name=$('#exam').val();
var class2= $('#class2').val();
if(valid){
window.location = 'marklist/export_marklist/'+ name+ '/'+ class2+'/';
}
}
},
{
"sExtends": "csv",
"sButtonText": "Export CSV"
},
{
"sExtends": "pdf",
"sButtonText": "Export to PDF",
'mColumns':mColumns
}
]
},
"sPaginationType": "bootstrap",
"aLengthMenu": [[10, 50, 100, 1000,5000,10000], [10, 50, 100, 1000,5000,10000]],
"iDisplayLength" : 5000,
"bFilter": true,
"aaSorting": [[ 0, "desc" ]],
"oLanguage": {
"sLengthMenu": "_MENU_",
"sSearch": ""
},
"fnPreDrawCallback": function() {
$(".loading").fadeIn();
},
"fnDrawCallback": function() {
$(".loading").fadeOut();
$('.po').popover({ html : true });
},
"fnCreatedRow": function( nRow, aData, iDisplayIndex ) {
if(tStatus){
$('td:last-child', nRow).html(tools.replace(/{id}/g,$('td:last-child', nRow).html()));
}
},
"fnInitComplete": function() {
$('.dataTables_filter input').attr("placeholder", "Search");
if(tStatus){
$('.po').popover({
html : true
});
}
var timeout = undefined;
// Anyone knows how to access table as JQuery object inside fnInitComplete?
// $('div.dataTables_filter input:text') works but it's not perfect solution in case
// you use multiple tables.
$('div.dataTables_filter input:text').unbind('keyup').bind('keyup', function() {
if (timeout != undefined) {
clearTimeout(timeout);
}
var $this = this;
timeout = setTimeout(function() {
timeout = undefined;
oTable.fnFilter($($this).val());
}, 500);
});
},
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
//aoData.push( { "name": "more_data", "value": "my_value" } );
$.getJSON( sSource, aoData, function (json) {
if(json.filtered_sum){
$('#filtered_sum').html(json.filtered_sum);
}
if(json.dt_params){
$("#btn-doprint").attr("onclick", json.dt_params);
}
if(json.filtered_total){
$.each(json.filtered_total, function(index, value) {
$('#'+index).html(value);
});
}
fnCallback(json)
} );
},
//tablesum
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var tablesum = String($(id).attr('tablesum'));
if (typeof tablesum !== 'undefined' && tablesum !== false) {
var arrTs = tablesum.split(",");
$(arrTs).each(function(index,value) {
var arrTsF = arrTs[index].split(":");
var total = 0;
for ( var i=0 ; i<aaData.length ; i++ )
{
var list_item = parseFloat(aaData[i][parseInt(arrTsF[1])]);
if(isNaN(list_item)){
list_item = 0;
}
total = total + list_item;
}
$("#" + arrTsF[0]).html(Math.round(total));
});
}
var tablecnt = String($(id).attr('tablecnt'));
if (typeof tablecnt !== 'undefined' && tablecnt !== false) {
var arrTs = tablecnt.split(",");
$(arrTs).each(function(index,value) {
var arrTsF = arrTs[index].split(":");
var totaltablecnt = 0;
for ( var i=0 ; i<aaData.length ; i++ )
{
var list_item = parseFloat(aaData[i][parseInt(arrTsF[1])]);
totaltablecnt++;
}
$("#" + arrTsF[0]).html(totaltablecnt);
});
}
}
});
if (typeof(column) != "undefined" && column!=false ) { fnShowHide(column,oTable); }
dt_server_api = oTable;
}
}
how to solve this?
Aucun commentaire:
Enregistrer un commentaire