⚠ 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

sellect all



maha

maha
  • profile picture
  • Member

Posted 06 April 2013 - 08:42 AM

I want to add sellect all checkbutton in grocery.

any help??


maha

maha
  • profile picture
  • Member

Posted 06 April 2013 - 09:40 AM

i know that it is found but i makes sum errors like

when i cheked the check all button the other buttons don,t checked  although it has checked attributs

this is print screen

grid.png?tsid=20130406-094013-f80f447c

any help?


maha

maha
  • profile picture
  • Member

Posted 06 April 2013 - 10:10 AM

other problem is when i press delet all button all rows deleted but after refresh one row deleted and the others still found

 

any help ??


davidoster

davidoster
  • profile picture
  • Member

Posted 06 April 2013 - 10:28 AM

I want to add sellect all checkbutton in grocery.

any help??

 

 

select all on what? rows in grid?

what theme do you use?


davidoster

davidoster
  • profile picture
  • Member

Posted 06 April 2013 - 10:30 AM

other problem is when i press delet all button all rows deleted but after refresh one row deleted and the others still found

 

any help ??

 

the photo doesn't display. include your controller's code to be able to help you.


maha

maha
  • profile picture
  • Member

Posted 06 April 2013 - 10:49 AM

grid.png?tsid=20130406-104928-ee05a2f


maha

maha
  • profile picture
  • Member

Posted 06 April 2013 - 11:23 AM

grid.png


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 07:38 AM

any help??


davidoster

davidoster
  • profile picture
  • Member

Posted 08 April 2013 - 08:16 AM

Two things you need to consider.

 

1. If there are more than one page at your list control by clicking 'Select All' selects the rows of the current page or all the rows of the table?

 

2. The code you are using does it have some other js that need to be included? If yes this is might be the reason that other stuff don't work on your page.

 

Why don't you use a simple jQuery like so, http://viralpatel.net/blogs/multiple-checkbox-select-deselect-jquery-tutorial-example/


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 08:44 AM

first- thank you for your help

second- the main proplem is the button "delete selected" delet just one row like the normal delete


davidoster

davidoster
  • profile picture
  • Member

Posted 08 April 2013 - 09:07 AM

you posted quite a few times so I missed that.

 

you need to go with jquery and get the row->id of each row and then via your model make a function that accepts an array of ids and deletes from the specific table the rows with these ids (or any other field you want).

 

in order to do that because you're on client side you need to make it via ajax!

This is something I made a couple of weeks back explaining this process...

1679_546307792075778_1869213850_n.jpg


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 09:18 AM

in groucery

theme/flixgrid/views/list.php

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('<?php echo $row->delete_url?>', { selection: list }, function(data) {
          document.write(list)
            alert('are you Sure to delet!');
	}); 
}

all checked rows found in list array

in grocery liberary

i made tow solution but they didn' work

first

protected function db_delete($state_info)
	{
		$primary_key 	= $state_info->primary_key;
		//// --->>>>> what i added
                $id_array = array();
                $selection = $this->input->post("selection", TRUE);
                $id_array = explode("|", $selection);
             ////-->>> End added
		if($this->callback_delete === null)
		{
			if($this->callback_before_delete !== null)
			{
				$callback_return = call_user_func($this->callback_before_delete, $primary_key);
				
				if($callback_return === false) 
				{
					return false;
				}
				
			}
			
			if(!empty($this->relation_n_n))
			{
				foreach($this->relation_n_n as $field_name => $field_info)
				{
					$this->db_relation_n_n_delete( $field_info, $primary_key );
				}
			}
			//// --->>>>> what i added		
			if(!empty($id_array))
                        {
                            foreach($id_array as $id)
                            {
                              
                               $delete_result = $this->basic_model->db_delete($id);
                            }
                          
                        }
                      ////-->>> End added
			$delete_result = $this->basic_model->db_delete($primary_key);
			
			if($delete_result === false)
			{
				return false;
			}
			
			if($this->callback_after_delete !== null)
			{
				$callback_return = call_user_func($this->callback_after_delete, $primary_key);
				
				if($callback_return === false) 
				{
					return false;
				}
				
			}				
		}
		else
		{
			$callback_return = call_user_func($this->callback_delete, $primary_key);
				
			if($callback_return === false) 
			{
				return false;
			}
		}
		
		return true;
	}	
	

second

 protected function db_delete($state_info)
	{
		$primary_key 	= $state_info->primary_key;
		////-->>>what i added
                $id_array = array();
                $selection = $this->input->post("selection", TRUE);
                $id_array = explode("|", $selection);
                print_r($selection);
                ////-->> end add
		if($this->callback_delete === null)
		{
			if($this->callback_before_delete !== null)
			{
				$callback_return = call_user_func($this->callback_before_delete, $primary_key);
				
				if($callback_return === false) 
				{
					return false;
				}
				
			}
			
			if(!empty($this->relation_n_n))
			{
				foreach($this->relation_n_n as $field_name => $field_info)
				{
					$this->db_relation_n_n_delete( $field_info, $primary_key );
				}
			}	
			////-->>>what i added	
			if(!empty($id_array))
                        {
                            
                           $delete_result = $this->basic_model->db_delete_all($id_array); 
                          
                        }
                //--->> end
			$delete_result = $this->basic_model->db_delete($primary_key);
			
			if($delete_result === false)
			{
				return false;
			}
			
			if($this->callback_after_delete !== null)
			{
				$callback_return = call_user_func($this->callback_after_delete, $primary_key);
				
				if($callback_return === false) 
				{
					return false;
				}
				
			}				
		}
		else
		{
			$callback_return = call_user_func($this->callback_delete, $primary_key);
				
			if($callback_return === false) 
			{
				return false;
			}
		}
		
		return true;
	}	
	

and in grocery_model

function db_delete_all($id_array)
    {
        //$this->db->empty_table($this->table_name);
        foreach ($id_array as $item) {
          $primary_key_field = $this->get_primary_key();
            $this->db->delete($this->table_name,array( $primary_key_field => $item));  
        }

        return true;
    }

davidoster

davidoster
  • profile picture
  • Member

Posted 08 April 2013 - 09:36 AM

Apparently you didn't understand what I said. This is all PHP code!

Where is the jQuery (javascript code) to make the AJAX calls on the client side in order to make it happen???

 

I suggest you read something like this in order to understand the basics, http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/

 

Sorry, but there isn't that much time available to me in order to review all the code you posted when you're clearly missing the proper way of doing it.

So, read here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 09:41 AM

thank you for help but i don,t profissional with jquery and ajax and i don,t want to change much in grocery .

any way thank you very much.


davidoster

davidoster
  • profile picture
  • Member

Posted 08 April 2013 - 10:28 AM

I have seen your code again.

 

Where did you get this db_delete function?

Is this the one that is included on your version of Grocery CRUD?


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 11:01 AM

yes?


davidoster

davidoster
  • profile picture
  • Member

Posted 08 April 2013 - 11:11 AM

Have you tried to follow this, /topic/421-multiple-delete-selection/ ?


maha

maha
  • profile picture
  • Member

Posted 08 April 2013 - 11:38 AM

that ia what i made put i made the function delet_selection in grocery liberary instede of controller


Zalo

Zalo
  • profile picture
  • Member

Posted 08 April 2013 - 18:08 PM

Sorry to meddle guys, but I think that probably the reason the delete all function is just deleting 1 is that all your checkboxes have the same name attribute. There fore when you do a post, either the first one sets the value or each one overrides the latter. An easy way to do this is to set the name like "custom_delete[]" with the [ ] at the end. That way, php treats it like an array of values instead of a single value. That way, you get an array with all the keys that you want to delete in the php, whenever is just one, some of them or all of them. All it's left is to verify you got values, implode(',', $post['custom_delete']) them, and delete where id in implode output.

 

To get that, you just get the list inside an html form, set the checkbox name as stated before and set the delete button to be the submit button. With this, you also skip the need of jQuery with the sole exception of the "check all" function.

 

 

Hope it helped.