waifung0207/ci_bootstrap_3

checkbox for multiple delete

Opened this issue · 2 comments

`<script type="text/javascript">
function deleteConfirm(){
var result = confirm("Do you really want to delete records?");
if(result){
return true;
}else{
return false;
}
}
$(document).ready(function(){
$('#check_all').on('click',function(){
if(this.checked){
$('.checkbox').each(function(){
this.checked = true;
});
}else{
$('.checkbox').each(function(){
this.checked = false;
});
}
});

$('.checkbox').on('click',function(){
    if($('.checkbox:checked').length == $('.checkbox').length){
        $('#check_all').prop('checked',true);
    }else{
        $('#check_all').prop('checked',false);
    }
});

});
</script>

	<table cellspacing="0" cellpadding="0" border="0" id="flex1">
	<thead>
		<tr class='hDiv'>
        	<th width="20px"><input type="checkbox" class="checkall" /></th>
			<?php foreach($columns as $column){?>
            <th width='<?php echo $column_width?>%'>
				<div class="text-left field-sorting <?php if(isset($order_by[0]) &&  $column->field_name == $order_by[0]){?><?php echo $order_by[1]?><?php }?>" 
					rel='<?php echo $column->field_name?>'>
					<?php echo $column->display_as?>
				</div>
			</th>
			<?php }?>
			<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
			<th align="left" abbr="tools" axis="col1" class="" width='20%'>
				<div class="text-right">
					<?php echo $this->l('list_actions'); ?>
				</div>
			</th>
			<?php }?>
		</tr>
	</thead>		
	<tbody>
$row){ ?>
	<?php
	$temp_string = $row->delete_url;
	$temp_string = explode("/", $temp_string);
	$row_num = sizeof($temp_string)-1;
	$rowID = $temp_string[$row_num];
	?>
	<tr  <?php if($num_row % 2 == 1){?>class="erow"<?php }?> id="custom_tr_<?=$rowID?>">
        <td><input type="checkbox" name="custom_delete" value="<?=$rowID?>" /></td>
		<?php foreach($columns as $column){?>
        <td width='<?php echo $column_width?>%' class='<?php if(isset($order_by[0]) &&  $column->field_name == $order_by[0]){?>sorted<?php }?>'>
			<div style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
		</td>
		<?php }?>
		<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
		<td align="left" width='20%'>
			<div class='tools'>				
				<?php if(!$unset_delete){?>
                	<a href='<?php echo $row->delete_url?>' title='<?php echo $this->l('list_delete')?> <?php echo $subject?>' class="delete-row" >
                			<span class='delete-icon'></span>
                	</a>
                <?php }?>
                <?php if(!$unset_edit){?>
					<a href='<?php echo $row->edit_url?>' title='<?php echo $this->l('list_edit')?> <?php echo $subject?>'><span class='edit-icon'></span></a>
				<?php }?>
				<?php 
				if(!empty($row->action_urls)){
					foreach($row->action_urls as $action_unique_id => $action_url){ 
						$action = $actions[$action_unique_id];
				?>
						<a href="<?php echo $action_url; ?>" class="<?php echo $action->css_class; ?> crud-action" title="<?php echo $action->label?>"><?php 
							if(!empty($action->image_url))
							{
								?><img src="<?php echo $action->image_url; ?>" alt="<?php echo $action->label?>" /><?php 	
							}
						?></a>		
				<?php }
				}
				?>					
                <div class='clear'></div>
	<script type="text/javascript">

$(function () {
//CHECK ALL BOXES
$('.checkall').click(function () {
$(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
});
//ADD DELETE BUTTON
if($('.pDiv2 .delete_all_button').length == 0) { //check if element already exists (for ajax refresh purposes)
$('.pDiv2').append('');
}
});

function delete_selected()
{
var list = "";
$('input[type=checkbox]').each(function() {
if (this.checked) {
//remove selection rows
$('#custom_tr_'+this.value).remove();
//create list of values that will be parsed to controller
list += this.value + '|';
}
});
//send data to delete
$.post('admin/User', { selection: list }, function(data) {
alert('Voila!');
});
}
</script>

	<table cellspacing="0" cellpadding="0" border="0" id="flex1">
	<thead>
		<tr class='hDiv'>
        	<th width="20px"><input type="checkbox" class="checkall" /></th>
			<?php foreach($columns as $column){?>
            <th width='<?php echo $column_width?>%'>
				<div class="text-left field-sorting <?php if(isset($order_by[0]) &&  $column->field_name == $order_by[0]){?><?php echo $order_by[1]?><?php }?>" 
					rel='<?php echo $column->field_name?>'>
					<?php echo $column->display_as?>
				</div>
			</th>
			<?php }?>
			<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
			<th align="left" abbr="tools" axis="col1" class="" width='20%'>
				<div class="text-right">
					<?php echo $this->l('list_actions'); ?>
				</div>
			</th>
			<?php }?>
		</tr>
	</thead>		
	<tbody>
$row){ ?>
	<?php
	$temp_string = $row->delete_url;
	$temp_string = explode("/", $temp_string);
	$row_num = sizeof($temp_string)-1;
	$rowID = $temp_string[$row_num];
	?>
	<tr  <?php if($num_row % 2 == 1){?>class="erow"<?php }?> id="custom_tr_<?=$rowID?>">
        <td><input type="checkbox" name="custom_delete" value="<?=$rowID?>" /></td>
		<?php foreach($columns as $column){?>
        <td width='<?php echo $column_width?>%' class='<?php if(isset($order_by[0]) &&  $column->field_name == $order_by[0]){?>sorted<?php }?>'>
			<div style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
		</td>
		<?php }?>
		<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
		<td align="left" width='20%'>
			<div class='tools'>				
				<?php if(!$unset_delete){?>
                	<a href='<?php echo $row->delete_url?>' title='<?php echo $this->l('list_delete')?> <?php echo $subject?>' class="delete-row" >
                			<span class='delete-icon'></span>
                	</a>
                <?php }?>
                <?php if(!$unset_edit){?>
					<a href='<?php echo $row->edit_url?>' title='<?php echo $this->l('list_edit')?> <?php echo $subject?>'><span class='edit-icon'></span></a>
				<?php }?>
				<?php 
				if(!empty($row->action_urls)){
					foreach($row->action_urls as $action_unique_id => $action_url){ 
						$action = $actions[$action_unique_id];
				?>
						<a href="<?php echo $action_url; ?>" class="<?php echo $action->css_class; ?> crud-action" title="<?php echo $action->label?>"><?php 
							if(!empty($action->image_url))
							{
								?><img src="<?php echo $action->image_url; ?>" alt="<?php echo $action->label?>" /><?php 	
							}
						?></a>		
				<?php }
				}
				?>					
                <div class='clear'></div>
			</div>
		</td>
		<?php }?>
	</tr>
	</tbody>
	</table>
</div>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $this->l('list_no_items'); ?>
<br/>
<br/>

these is the list.php`

below code i had inserted in controller
function delete_selection()
{
$user_id_array = array();
$selection = $this->input->post("selection", TRUE);
$id_array = explode("|", $selection);

foreach($user_id_array as $item):
if($item != ''):
//DELETE ROW
$this->db->where('name', $item);
$this->db->delete('users');
endif;
endforeach;
}

I am not able to delete multiple users kindly can you help me out fast its urgent