⚠ 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

Add Action with Edit Page



hunterbit
  • profile picture
  • Member

Posted 02 March 2012 - 00:57 AM

[color=#333333][font=arial, sans-serif][size=4]Hello everyone[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4],[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I wanted to know[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]if I add[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]an action[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]to[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]a button[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]I can[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]bring up[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]with[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]just the[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]grocery[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]edit page[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]and[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]not the list[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]?[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]Let me give an[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]example for[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]me to understand[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]better.[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I have a table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]where [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]users[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] are [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]all[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] user data[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] and a [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]destination[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]where there are [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]other data[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]users[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]action [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]that I make [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]I want[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] to make me[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] go to the page[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] by clicking[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] the edit[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I hope[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4] I explained myself[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color]

[color=#333333][font=arial, sans-serif][size=4]Thank you.[/size][/font][/color]

KaBaDaBrA
  • profile picture
  • Member

Posted 02 March 2012 - 07:05 AM

Hi - web-johhny just added ids to the div tags so you can insert your own action buttons using Javascript/jQuery a lot easier. Be sure to download the latest files from github to make use of it :)

A quick example of adding a quick button calling a custom javascript function:


$(document).ready(function(){
$('.pDiv').append('<div class="form-button-box"><input type="button" value="Custom" onclick="javascript: custom_function()"></div>');
});


also you can specify which state to add it to. For example if you want to just use the "edit" state and not the "list" state you can do something like this:


$state = $this->grocery_crud->getState();



if($state == "edit") {
//insert your code here - will only display on the edit state
}

hunterbit
  • profile picture
  • Member

Posted 04 March 2012 - 00:27 AM

[left][color=#333333][font=arial, sans-serif][size=4]Hello and [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]thanks for your [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]reply[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I do not understand [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]your example[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]. [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]However,[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]I try [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]to [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]explain.[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I have a table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]with all the [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]additional info META [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]of the various [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]existing accounts[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]Then [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]associated [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]the [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]META [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]USER S[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]contain in g[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]all the de tails [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]of access and [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]login[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]I have now [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]created a[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]way to see [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]the page [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]for LIST[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]/[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]EDIT [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]the table [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]and would like to [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]add a [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]META [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]add_action [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]like this[/size][/font][/color][/left]
[left]

$this->grocery_crud->add_action('Account', '', '', 'ui-icon-image', array($this, 'elencoAccount'));
[/left]
[left][color=#333333][font=arial, sans-serif][size=4]I [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]should [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]see [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]a page of [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]EDIT to [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]change the data [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]access[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]. [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]with what [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]you suggested [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]I do not understand [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]how to [/size][/font][/color][color=#333333][font=arial, sans-serif][size=4]do this[/size][/font][/color][color=#333333][font=arial, sans-serif][size=4].[/size][/font][/color]
[color=#333333][font=arial, sans-serif][size=4]thanks[/size][/font][/color][/left]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 10:18 AM

The code that you have will not work. To the last segment you have a callback that doesn't exist [ array($this, 'elencoAccount') ] . You simply (as I understood) want the edit to redirect you to another page right? And not the default grocery CRUD edit (If not please copy your function and your table just to understand what you mean).
So in this case you need something like this:

for datatables theme:

$crud->add_action('Edit', '', 'your_controller/your_method','ui-icon-pencil');


and for flexigrid theme:


$crud->add_action('Edit', base_url().'assets/grocery_crud/themes/flexigrid/css/images/edit.png', 'your_controller/your_method');


So the result will be for example:

your_controller/your_method/34 (34 is the primary id)
your_controller/your_method/85
your_controller/your_method/99
....

hunterbit
  • profile picture
  • Member

Posted 04 March 2012 - 10:46 AM

Thanks again for your timely responses.
I have two tables with a 1 to 1 where the META table contains the information of the person while the USERS table contains the account information associated with the person.
In my backend I have a link that invokes the controller to display the list generated by META groceryCRUD referring to the table. In this table would add a new action that makes me open the edit page of the table USERS associated with the META table. The page of EDIT must always be to groceryCRUD.
Below the code table META

public function elencoUtenti() {
// controlla se lo user fa parte del gruppo admin esegue
// la funzione altrimenti viene reinviato alla pagina di login
$this->checkAdmin();
$data = array(
'titolo' => 'ADMIN AREA - UTENTI',
'sezione' => 'ELENCO UTENTI',
);
// configurazione lista
$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->set_table('meta')
->set_subject('Utente')
->columns('nome', 'cognome', 'ragioneSociale', 'tipo')
->display_as('ragioneSociale', 'Ragione Sociale');
// configurazione relazioni
$this->grocery_crud->set_relation('comune', 'italy_comune', 'denominazione');
$this->grocery_crud->set_relation('provincia', 'italy_provincia', 'denominazione');
// configurazione edit
$this->grocery_crud->fields('nome', 'cognome', 'ragioneSociale', 'piva', 'comune', 'provincia', 'indirizzo', 'telefono', 'cellulare', 'fax', 'newsletter', 'notificaEmail', 'notificaSms');
//$this->grocery_crud->required_fields('titolo','descrizione','visibile');
//$this->grocery_crud->set_field_upload('srcImage','public/uploads/images');
// Callback per recuperare il valore del tipo di utente ed inserirlo nella cella adeguato
// ed avere quindi una visione rapida di quali utenti sono amministratori e quali no
$this->grocery_crud->callback_column('tipo', array($this, 'tipologiaUtente'));
// Aggiungiamo Action personalizzate
$this->grocery_crud->add_action('Account', '', '', 'ui-icon-image', array($this, 'elencoAccount'));
$output = $this->grocery_crud->render();
$this->load->view('admin/variabili', $data);
$this->load->view('admin/elenco-files', $output);
}


and here code for open EDIT page

public function elencoAccount() {

//insert here code EDIT PAGE

}

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 10:57 AM

Now I understood. So you if you want a fast solution for this is the code below:


function elencoAccount($primary_key , $row)
{
//The primary key is in your case the primary key value for the meta.
$user = $this->db->where('meta_id',$primary_key)->get('users')->row();

$user_id = $user->id;

return site_url('your_controller/users/edit/'.$user_id);
}


If you still don't want the fastest solution and you need a better solution to not do so many queries, I Suggest the code below:


function elencoAccount($primary_key , $row)
{
return site_url('your_controller/quick_user_redirect/'.$primary_key);
}

function quick_user_redirect($meta_id)
{
$user = $this->db->where('meta_id',$meta_id)->get('users')->row();
$user_id = $user->id;
return site_url('your_controller/users/edit/'.$user_id);
}

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 11:01 AM

Or else :


function elencoAccount($primary_key , $row)
{
return site_url('your_controller/users/edit/'.$row->user_id);
}

hunterbit
  • profile picture
  • Member

Posted 04 March 2012 - 11:27 AM

ok. your code it's ok but now there is two problem.
my edit page has link BACK TO LIST that invoke this url controller/users but I want that this link invoke url controller/meta because I want view META LIST PAGE.
The second problem is that in the edit page I see all the fields and I would decide which fields to show and what not.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 13:08 PM

And there you can use the code as @KaBaDaBrA said before. At the users page, after the render function you can have:


$output = $crud->render();

$state = $crud->getState();
if($state == 'list')
{
redirect('your_controller/elencoUtenti');
}


and also of course you can decide which fields to show or not with the simple $crud->fields method as normal.

You can see an example of how the $crud->fields works at: http://www.grocerycr...es/full_example

carlinchisart
  • profile picture
  • Member

Posted 05 April 2012 - 20:44 PM

Hi, all if i understand ok this topic, i hava one question.

how i can, redirect to other page when the user insert a data, i try to use callback_after_insert(array($this,'mensajeConfirmacion'));

and this function

function mensajeConfirmacion($datos,$key){
$nombre=$datos['nombre_usuario'];
return site_url('usuario/registro/mostrarExitoRegistro/'.$nombre.'/'.$key);
}
function mostrarExitoRegistro($datos,$key){
$arreglo['key']=$key;
$arreglo['nombre']=$datos;
$this->load->view('usuario/solicitudRegistrada_view.php',$arreglo);
}


but this no work, so, how i can do this? a redirect to other page when insert a data, only when insert.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 April 2012 - 10:11 AM

You can see a related post to this at: http://www.grocerycr...p__246#entry246

If you want only for add just change the [color=#282828][font=helvetica, arial, sans-serif]datatables-add.js file[/font][/color]

carlinchisart
  • profile picture
  • Member

Posted 09 April 2012 - 13:38 PM

HI @web-johnny, more more thanks for your answers, i try to fine topic about this but my search was not good, in this moment i can't to try the code, but i have one question, this redirect work for all forms that i use with grocery crud? or i can to referens used any id to the form that i need the redirect? i need this redirect only in one of the forms. i don't know if the change in js file affect all add forms.

thanks.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 April 2012 - 19:34 PM

Yes this solution will affect all the forms.

If you want to affect only one form the only way to do it without changing the core of grocery CRUD is the below (I know it is not the right way, but if it's only for one form it's ok ;)):


$crud->set_lang_string('insert_success_message',
'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
<script type="text/javascript">
window.location = "'.site_url(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
</script>
<div style="display:none">
'
);

carlinchisart
  • profile picture
  • Member

Posted 11 April 2012 - 14:34 PM

Thanks!!! @web-jhonny, i have to do a little change in my application, becouse i have to do an accessibility web site, so I post in other topic, if i have question, and the conclusions.

Felipe Matos
  • profile picture
  • Member

Posted 24 January 2014 - 00:02 AM

Hi - web-johhny just added ids to the div tags so you can insert your own action buttons using Javascript/jQuery a lot easier. Be sure to download the latest files from github to make use of it :)

A quick example of adding a quick button calling a custom javascript function:
 

$(document).ready(function(){
	$('.pDiv').append('<div class="form-button-box"><input type="button" value="Custom" onclick="javascript: custom_function()"></div>');
});
also you can specify which state to add it to. For example if you want to just use the "edit" state and not the "list" state you can do something like this:

$state = $this->grocery_crud->getState();
if($state == "edit") {
	//insert your code here - will only display on the edit state
}
Hi KaBaDaBrA,
 
Could you explain better. For example, where I put the JQuery code, and where is the record id variable that I am editing. 
 
I Would like add a delete button in edit form.
 
Thank you!