我遇到一个问题,从不同页面的jquery数据表中选择多个成员,如果我从第一页选择2个成员,从第二页选择2个,当我返回第一页时,值复选框是当我回到第二页时,没有勾选并且相同。搜索数据表时也会发生同样的事情。可能是什么问题?我将在下面发布我的Controller,Model,View和Datatable JS:
查看:
<div class="col-md-12"><?php echo $this->table->generate(); ?></div>
控制器:
$tmpl = array ( 'table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="table table-striped">' );
$this->table->set_template($tmpl);
$this->table->set_heading('<input type="checkbox" id="selAll" name="select_all" />','Customer Name','Email','Phone');
MODEL:
public function list_customers($center_id ='',$course_id =''){
$this->datatables->select("customer_id, CONCAT_WS( ' ' , firstname , lastname ) as firstname, email ,phone")->where('is_disable',0)
->edit_column('customer_id', input_checkbox('customer_id[]' ,'$1' ),'customer_id')->from($this->_table_name);
if(!empty($center_id)) $this->db->where('category',$center_id);
if(!empty($course_id)){
$this->db->where('customer_id IN (select customer_id from `dance_customer_course` WHERE dance_customer_course.`festival_id` = '.$course_id.')');
}
return $this->datatables->generate();
}
DATATABLE(JS):
<script type="text/javascript">
$(document).ready(function() {
$("#sform").submit(function(){
if($('.checkbox:checked').length < 1){
alert("Please select the customer");
return false
}
if($('#content').val() == ''){
alert("Please enter content");
return false
}
});
var oTable = $('#big_table').dataTable( {
"bProcessing": true,
"bInfo": false,
"bServerSide": true,
"sAjaxSource": '<?php echo base_url(); ?>sendsms/list_customers',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ":20,
"oLanguage": {
"sProcessing": "<img src='<?php echo base_url(); ?>img/ajax-loader.gif'>"
},
"fnInitComplete": function() {
//oTable.fnAdjustColumnSizing();
},
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
});
$('#selAll').click(function(e){
if (e.stopPropagation) e.stopPropagation();
var checkBoxes = $(".checkbox");
if(checkBoxes.prop("checked")) $(this).text("Check All");
else $(this).text("Uncheck All");
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
});
这几乎是我使用的代码,有人可以帮助我吗?谢谢。
答案 0 :(得分:0)
尝试这个
$('input[type=checkbox]').each(function () {
newvalue = ( $(this).val());
if (this.checked) {
do your code
}
do what you want
});