⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to make checkbox in each cell of crud



php_lover
  • profile picture
  • Member

Posted 23 February 2013 - 11:31 AM

how to make checkbox in cell of grocerrycrud  for input 


sachin vairagi
  • profile picture
  • Member

Posted 23 February 2013 - 14:10 PM

hi php_lover,

 

do you want checkbox for multiple delete?


sachin vairagi
  • profile picture
  • Member

Posted 23 February 2013 - 14:13 PM

Here is the very nice post from KaBaDaBrA, you can try it.

 

 

Anyway here we go:

post-756-0-02867000-1336592715_thumb.png


Above is an example, added the check links to the side and a
delete all selected button to the bottom right. Here is the "list.php"
file, download it and copy to your flexigrid theme (backup your current
one) path: assets\grocery_crud\themes\flexigrid\views.

php.gif
 list.php   4.02K
  253 downloads

You will need to edit the javascript part around line 25 and replace your own URL in here.

Here's an example function for the controller:

function delete_selection()
{
   $id_array = array();
   $selection = $this->input->post("selection", TRUE);
   $id_array = explode("|", $selection);

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


php_lover
  • profile picture
  • Member

Posted 26 February 2013 - 06:56 AM

i want checkbox for selecting role from grid just like this i want to assign privelage to one use that he can add edit delete record from database so i want checkbox for this its kind of master detail datagrid and once again thanks@Sachin101


Гэрэлт-Од Гоцбаяр
  • profile picture
  • Member

Posted 27 February 2013 - 14:33 PM

Thanks


php_lover
  • profile picture
  • Member

Posted 28 February 2013 - 10:45 AM

Sorry for bad english actually i have a grid with colum add edit delete export i have to assighn the role of every employee so i want to use checkbox instead of textbox how it is possible


php_lover
  • profile picture
  • Member

Posted 28 February 2013 - 10:56 AM

and also checkbox not showing on grid


Christophe Conduché
  • profile picture
  • Member

Posted 26 April 2013 - 10:19 AM

Very nice Post, I have bookmarked KaBaDaBra as he gave so many useful tricks and tips... Thks !!

 

 

I have 2 questions :

 

1) how to have this list.php only assigned to some of the lists ?  make a copy of the theme and use different themes at different places ?

 

 

2) is it possible to have 2 columns of checkboxes with different callbacks (for multiple deletion as it is or multiple "grouping" actions) ?

 

a start could be :

            	<th width="20px"><input type="checkbox" class="checkall" /></th>
            	<th width="20px"><input type="checkbox" class="checkall2ndcolumn" /></th>



            <td><input type="checkbox" name="custom_delete" value="<?=$rowID?>" /></td>
            <td><input type="checkbox" name="custom_action" value="<?=$rowID?>" /></td>


but then, the functions at the beginning have to be modified as they select all base on the type of the input (checkbox) rather than base on the name or class

 

<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('<input type="button" value="Delete Selected" class="delete_all_button" onclick="delete_selected();">');
	}
});

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('http://localhost/grocery_crud/index.php/examples/delete_selection', { selection: list }, function(data) {
		alert('Voila!');
	});
}
</script>

 

 

3) How to use "site_url" there rather than localhost in the url ? it is client sidejavascript there, is there a function availble on client side to get the site url ?

	//send data to delete
	$.post('http://localhost/grocery_crud/index.php/examples/delete_selection', { selection: list }, function(data) {
		alert('Voila!');


davidoster
  • profile picture
  • Member

Posted 26 April 2013 - 11:17 AM

1. this list.php is a view file, so you use it where ever you want to display this via your controller like this, $this->load->view('list.php', $your_data);

2. something like what you suggest, you will need to make unique names or an array. just experiment

3. within a view file like list.php you can use the <?php ?> notation in order call a function. the code you need is <?php echo site_url(); ?> site_url() is a CodeIgniter function.


Christophe Conduché
  • profile picture
  • Member

Posted 26 April 2013 - 15:20 PM

2. ok

3. ok

 

1.   humm, not sure to see exactly...  I use mainly this :

        $output = $this->grocery_crud->render();
 
        $this->_vdoman_output($output);        
    }
 
    function _vdoman_output($output = null)
 
    {
        $this->load->view('gestpara_template_desk.php',$output);    
    }

but, no where I go into a place where I have to call list.php myself and can override it.

 

may be I can create a copy of flexigrid theme, let be "original" and call it flexigrid2, but the patched list.php file and use $this->grocery_crud->set_theme("flexigrid2").


hariprasath
  • profile picture
  • Member

Posted 07 October 2013 - 11:12 AM

Hi,

 

I need help!

 

checkbox Working fine for me, but i need to how  hide/remove from Other List Pages. Its show on unwanted palces.

 

Im Very New to This Please help!

 

Thanks


ssomenzi
  • profile picture
  • Member

Posted 15 October 2013 - 19:17 PM

Hi,

 

pretty ugly workaround, but if you need to use your modified list.php only on specific pages you can

1. duplicate your theme

2. assign a new name to the duplicated theme

3. modify the list.php file

4. call $crud->set_theme('duplicated_theme_name'); before rendering the crud only on the pages where you need the additional functions in you list.php file.

 

Hope it helps.

S.


Robert
  • profile picture
  • Member

Posted 16 October 2013 - 05:43 AM

I think is better to modifie GC to use specific view file and jest duplicate and change the view name .. i was working on something like that is i can make it i will post the code.