clicking TableTools buttons resets my table data and display only table headings
clicking TableTools buttons resets my table data and display only table headings
Niaz
Posts: 1Questions: 1Answers: 0
I am using Codeigniter and bootstrap. any suggestion will be appreciated.
## HTML
<div class="tab-content">
<!----TABLE LISTING STARTS-->
<div class="tab-pane active" id="list">
<div class="form-group">
<label for="class_id" class="col-sm-2 control-label"><?php echo get_phrase('Select Class');?></label>
<div class="col-sm-4">
<select name="class_id" class="form-control" data-validate="required" id="class_id"
data-message-required="<?php echo get_phrase('value_required');?>"
onchange="return get_class_sections(this.value)">
<option value=""><?php echo get_phrase('select class');?></option>
<?php
$classes = $this->db->get('class')->result_array();
foreach($classes as $row):
?>
<option value="<?php echo $row['class_id'];?>">
<?php echo $row['name'];?>
</option>
<?php
endforeach;
?>
</select>
</div>
</div>
<div class="form-group">
<label for="section_id" class="col-sm-2 control-label"><?php echo get_phrase('Select Section');?></label>
<div class="col-sm-4">
<select name="section_id" class="form-control" id="section_selector_holder" onchange="return get_class_routines(this.value)">
<option value=""><?php echo get_phrase('select_class_first');?></option>
</select>
</div>
</div>
<table class="table table-bordered datatable" id="table_export">
<thead>
<tr>
<th>Day</th>
<th>Subject</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody id="putresponse">
</tbody>
</table>
## JavaScript
<script type="text/javascript">
jQuery(document).ready(function($)
{
var datatable = $("#table_export").dataTable({
"sPaginationType": "bootstrap",
"sDom": "<'row'<'col-xs-3 col-left'l><'col-xs-9 col-right'<'export-data'T>f>r>t<'row'<'col-xs-3 col-left'i><'col-xs-9 col-right'p>>",
"oTableTools": {
"aButtons": [
{
"sExtends": "xls",
"mColumns": [0, 1, 2, 3]
},
{
"sExtends": "pdf",
"mColumns": [0, 1, 2, 3]
},
{
"sExtends": "print",
"fnSetText" : "Press 'esc' to return",
"fnClick": function (nButton, oConfig) {
//datatable.fnSetColumnVis(6, false);
this.fnPrint( true, oConfig );
window.print();
$(window).keyup(function(e) {
if (e.which == 27) {
datatable.fnSetColumnVis(4, true);
}
});
},
},
]
},
});
$(".dataTables_wrapper select").select2({
minimumResultsForSearch: -1
});
});
</script>
<script type="text/javascript">
function get_class_routines(section_id) {
var e = document.getElementById("class_id");
var class_id = e[e.selectedIndex].value;
$.ajax({
url: '<?php echo base_url();?>index.php?admin/get_class_routiness/'+section_id+'/' + class_id,
success: function(response)
{
jQuery('#putresponse').html(response);
}
});
}
</script>
## Controller
function get_class_routiness($section_id, $class_id){
$query = $this->db->get_where('class_routine', array('class_id' => $class_id , 'section_id' => $section_id ))->result_array();
if($query){
// $html_return = "";
foreach ($query as $routine) {
$html_return .="<tr><td>";
$html_return .= $routine['day'];
$html_return .="</td><td>";
$html_return .= $this->crud_model->get_type_name_by_id('subject',$routine['subject_id']);
$html_return .="</td><td>";
$html_return .= $routine['time_start'];
$html_return .= "</td><td>";
$html_return .= $routine['time_end'];
$html_return .="</td></tr>";
}
echo $html_return;
} else {
echo 'No record';
}
}
This discussion has been closed.