⚠ 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 dropdown in grid ?



karim_h
  • profile picture
  • Member

Posted 09 October 2012 - 17:03 PM

Hi,

I have tables: products and categories and I display list of products in the grid. is there a possibility to make a filter (eg products by category) in a dropdown??

Thanks.

victor
  • profile picture
  • Member

Posted 09 October 2012 - 17:46 PM

HI! You can use a function.
http://www.grocerycr...functions/where

for example:
$crud->where('category_id', $this->uri->segment(3));
next step:
create dropdown in your template

karim_h
  • profile picture
  • Member

Posted 09 October 2012 - 23:59 PM

thank you M. Victor for your answer ^^

what callback function you mean sir ?

victor
  • profile picture
  • Member

Posted 10 October 2012 - 06:37 AM

I mean http://www.grocerycr...unctions/where.
Sorry for the inaccuracy, i edited my post

karim_h
  • profile picture
  • Member

Posted 10 October 2012 - 10:59 AM

[size=4][font=comic sans ms', cursive][b][color=#282828]thank you M. Victor,[/color][/b][/font][/size]
[size=4][font=comic sans ms', cursive][b][color=#282828]sorry but i don't know where should create dropdown [/color][/b][/font][/size]
[size=4][font=comic sans ms', cursive][b]is that in [color=#282828] ([/color][color=#ff0000]assets\grocery_crud\themes\datatables\views\list_template[/color] )[/b][/font][/size]

[size=4][font=comic sans ms', cursive][b]or ([color=#ff0000]assets\grocery_crud\themes\datatables\views\list[/color] )[/b][/font][/size]
[b]And how i can fill this dropdown from my table ? [/b]
[b]if you can show me an example .[/b]
[b]Thank you very much sir for your time..[/b]

victor
  • profile picture
  • Member

Posted 10 October 2012 - 11:32 AM

controller:

function manager()

{
// your settings for grocery crud
$crud = new g..
$crud->....

if($this->uri->segment('3')=='category')
{
$crud->where('category_id',$this->uri->segment('4'));
}
$output = $crud->render();
// object into array
$this->data['crud'] =(array)$output;
$this->data['categories'] = $this->db->get('categories');
$this->load->view('your_template',$this->data);
}

template:

<html>
<head>
<meta charset="utf-8"/>
<?php
if($crud['css_files']):foreach($crud['css_files'] as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; endif;?>
<?php
if($crud['js_files']): foreach($crud['js_files'] as $file): ?>
&lt;script src="<?php echo $file; ?>"></script>

<?php endforeach; endif;?>
&lt;script>
function Menu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
</head>
<body>
<div>
<form name="form" id="form" >

<select name="go" id="go" &#111;nchange="Menu('parent',this,0)" style="width:300px;">
<? if($categories):foreach($categories as $item):?>
<option value="admin/articles/category/<?= $item['id'] ?>" >
<?= $item['title']; ?>
</option>
<? endforeach;endif;?>
</select>
</form>
</div>
<div >
<?= $crud['output']; ?>
</div>
</body>
</html>

[attachment=310:a.jpg]

karim_h
  • profile picture
  • Member

Posted 10 October 2012 - 13:40 PM

thank u M. Victor

an error throw undefined variable Item
i explain what i realy want

i have tables : notifications(id,texte,date,status,application_id) , applications (id,title,versio,......)
i want retreiving notification by application .

Can you sir read this and thank u very much ^_^
My code is
controller : name : mynotification



[quote]
public function notifications() {

$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->where('status','inactive');
// $crud->where('application_id',$this->uri->segment(3));
$crud->set_table('notifications');
$crud->columns('id','texte','date_creation','application_id');
$crud->display_as('application_id','application_name');
$crud->set_subject('Notifications');
$crud->unset_add_fields('status');
$crud->required_fields('texte');

$crud->set_relation('application_id','applications','title');
$crud->unset_print();
if($this->uri->segment('3')=='application_id')
{
$crud->where($this->uri->segment('4'));
}
$output = $crud->render();
// object into array
$this->data['crud'] =(array)$output;
$this->data['categories'] = $this->db->get('applications');
$this->load->view('my_notification_view',$this->data);

}
[/quote]

and my template :

[quote]
..
...
.

<div>
<form name="form" id="form" >

<select name="go" id="go" onchange="Menu('parent',this,0)" style="width:300px;">
<? if($categories):foreach($categories as $item):?>
<option value="mynotifications/notification/<?= $item['id']; ?>" >
<?= $item['title']; ?>
</option>
<? endforeach;endif;?>
</select>
</form>
</div>
<div width="100" height="100" >


<a href='<?php echo site_url('myapplication/application')?>'>+ Add Application</a>
<?= $crud['output']; ?>

</div>

[/quote]

[img]C:UsersAdminDownloadsexample.png[/img]

Dayanand
  • profile picture
  • Member

Posted 23 October 2012 - 04:28 AM

[attachment=324:DataTable.png]Hi Victor,This is dayanand...

I am new to crud data table. i am implemented the drop in view as per your above suggestion but once select any drop down the page was reloading and its taking too much time... It is possibilities in ajax load.Actually i am using your default latest pack customer,product,films and category table... When i select films it will list of film with different category in list... actually i want to integrate already search field is there in this pack but i want one drop down for category and search text field. if any one select any category from drop down in that filter with text fileld.

Please check with attachment.

I am waiting for you...


Thank you
Dayanand

zrmba
  • profile picture
  • Member

Posted 02 February 2013 - 11:06 AM

Till in trouble for that?
I tried this:

function versements($primary_key = '')
{
$crud = new grocery_CRUD();

if ($primary_key != '')
{
$crud->where('cotisations_idcotisations',$primary_key);
}
$this->db
->select('nom, prenom, designation, taux as cot_amount, max(date_cotisation) as derniere_coti, sum(montant_cotise) as sum_coti')
->join('cotisations', 'cotisations.idcotisations = membres_cotise.cotisations_idcotisations')
->join('membres', 'membres.idmembres = membres_cotise.membres_idmembres')
->group_by('membres_idmembres', 'cotisations_idcotisations')
->order_by('membres_idmembres', 'desc');
$crud->set_table('membres_cotise');
$crud->set_subject('Cotisations');
$crud->columns( 'nom', 'prenom', 'designation', 'cot_amount', 'sum_coti', 'derniere_coti');


$output = $crud->render();

$this->_tontine_output($output);
}


That is a function of my controller.
Then in my view:

<?php $crud = new grocery_CRUD();
//echo $this->uri->segment(2);
if ($this->uri->segment(2) == 'versements') { ?>
<form name="form" id="form" style="margin:0 auto 8px auto;">
<select name="go" id="go" onchange="Menu('parent',this,0)" style="width:300px;">
<option value="" >Choisir la cotisation</option>
<?php

$this->db->select('idcotisations, designation');
$tontines = $this->db->get('cotisations');
if(isset($tontines)):foreach($tontines->result() as $item):?>
<option <?php if (($this->uri->segment(3)!='')&&($this->uri->segment(3) == $item->idcotisations )) echo 'selected'; ?> value="<?php echo base_url() .'index.php/tontine/versements/'. $item->idcotisations ?>" ><?php echo $item->designation; ?></option>
<?php endforeach;endif; echo $tontines ;?>
</select>
</form>
<?php } ?>

This is to show the dropdown only in the specific action.

Then at last, till in the head of my view:

function Menu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

Not too professional, but it works!

Hope it helps you.