Add Action with Edit Page
- Single Page
Posted 02 March 2012 - 00:57 AM
[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]
Posted 02 March 2012 - 07:05 AM
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
}
Posted 04 March 2012 - 00:27 AM
[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]
[/left]
$this->grocery_crud->add_action('Account', '', '', 'ui-icon-image', array($this, 'elencoAccount'));
[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]
Posted 04 March 2012 - 10:18 AM
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
....
Posted 04 March 2012 - 10:46 AM
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
}
Posted 04 March 2012 - 10:57 AM
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);
}
Posted 04 March 2012 - 11:01 AM
function elencoAccount($primary_key , $row)
{
return site_url('your_controller/users/edit/'.$row->user_id);
}
Posted 04 March 2012 - 11:27 AM
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.
Posted 04 March 2012 - 13:08 PM
$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
Posted 05 April 2012 - 20:44 PM
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.
Posted 09 April 2012 - 10:11 AM
If you want only for add just change the [color=#282828][font=helvetica, arial, sans-serif]datatables-add.js file[/font][/color]
Posted 09 April 2012 - 13:38 PM
thanks.
Posted 09 April 2012 - 19:34 PM
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">
'
);
Posted 11 April 2012 - 14:34 PM
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 }