⚠ 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

[updated 14.11.2012] Grid view with dropdown list of categories in header (library)



victor
  • profile picture
  • Member

Posted 10 November 2012 - 00:05 AM

Hi all!
I created a library which adds a drop-down menu of categories into the grid header.
[color=#66cc00]___________________________________________[/color]
Download here:
[attachment=356:grocery_crud_categories.php]
updated 14/11/2012
[color=#66cc00]___________________________________________[/color]

You can do the sorting by category by means of the menu (without Ajax yet)
This library supports single-level lists and adjacency list tree.
[b]And most importantly, this library do not require changes to the view![/b]
[attachment=342:a.jpg][attachment=343:b.jpg]

[b]How to use:[/b]


function goods()
{
$this->load->library('grocery_CRUD');
$this->load->library('grocery_crud_categories') ;
$crud = new grocery_CRUD();
$crud->set_relation('goods_category','adj_category','category_name');
$crud->set_table('adj_goods');

$config = array(
'table_name'=>'adj_goods',
'related_table'=>'adj_category',
'sort_field'=>'goods_category',
'categories_primary_key'=>'category_id',
'related_title_field'=>'category_name',
'parent_field'=>'parent_id',
'order_by'=>'category_name',

'first_url' => base_url().__CLASS__.'/'.__FUNCTION__,
'segment_name' => 'category';
'style' => 'height:24px; width: 200px;',
'class'=>'your_class',
'text'=>array('all_rows'=>'select category');
);

$categories = new grocery_crud_categories($crud,$config);

//Attention! Don't use the $crud->render();
//Use the $categories->render();
// But there is second method. You can read about that below.

$output = $categories->render();
$this->_example_output($output);
}


[b]The second method of integrate.[/b]

$categories = new grocery_crud_categories($crud,$config);
$dropdown = $categories->get_dropdown();

$output = $crud->render();
$output->output = $dropdown . $output->output;
$this->_example_output($output);


[b]Config:[/b]

[indent=1][color=#ff0000]1)[/color][color=#ff0000]*[/color][color=#ff0000] [/color]'[color=#8b4513]table_name[/color]'=>'adj_goods',
[color=#ff0000]2)[/color][color=#ff0000]*[/color] '[color=#8b4513]related_table[/color]'=>'adj_category',
[color=#ff0000]3)[/color][color=#ff0000]*[/color] '[color=#8b4513]sort_field[/color]'=>'goods_category',
[color=#ff0000]4)[/color][color=#ff0000]*[/color] '[color=#8b4513]categories_primary_key[/color]'=>'category_id',
[color=#ff0000]5)[/color][color=#ff0000]*[/color] '[color=#8b4513]related_title_field[/color]'=>'category_name',
[color=#ff0000]6)[/color] '[color=#8b4513]parent_field[/color]'=>'parent_id', - [color=#ff0000]if you use a single-level list set this param as [/color][color=#0000ff]"false",[/color][/indent]

[indent=1]click -> [attachment=346:how.jpg][/indent]
[indent=1][color=#ff0000]7)[/color] '[color=#8b4513]order_by[/color]'=>'category_name' - lets you set an ORDER BY clause. Example: 'order_by'=>"position DESC,name ASC"[/indent]
[indent=1][color=#ff0000]8)[/color][color=#ff0000]* [/color]'[color=#8b4513]first_url'[/color] => base_url().__CLASS__.'/'.__FUNCTION__ - base url for the links[/indent]
[indent=1][color=#ff0000]9)[/color]'[color=#8b4513]segment_name[/color]' = 'category'; - segment name. http://localhost/examples/goods/[color=#ff0000]category[/color]/[color=#0000ff]7[/color][/indent]
[indent=1]
[color=#ff0000]10)[/color] '[color=#8b4513]style[/color]' => 'height:24px; width: 200px;' - you can use your styles for this menu
[color=#ff0000]11) [/color]'[color=#8b4513]class[/color]'=>'your_class' - you can use a class too[/indent]
[indent=1][color=#ff0000]12) [/color]'[color=#8b4513]text[/color][color=#daa520]'[/color]=>array('all_rows'=>'all categories') - text for the first element of list ( "<option>all categories</option>")[/indent]

[indent=1][color=#ff0000]*[/color] - element is required.[/indent]
[indent=1]-----------------------------------[/indent]
[indent=1]I created this library for the flexigrid theme, but it works with the datatable (you can modify the code as you like ;) ).[/indent]
[indent=1]P.S: If you have suggestions for improving the library, I will be glad to hear. :)[/indent]
[indent=1]P.S.S. Code can contain some bugs :ph34r:. If you find a bug - report, please.[/indent]
[indent=1]Sorry, my English is bad :(.[/indent]

tlc033
  • profile picture
  • Member

Posted 10 November 2012 - 19:08 PM

10+++ THX. I well test it.

victor
  • profile picture
  • Member

Posted 12 November 2012 - 16:54 PM

Today the library will be updated a little :)

tofayelahmed
  • profile picture
  • Member

Posted 14 November 2012 - 05:33 AM

Hi victor, Thanx for your library.
But when iimplement this ,its generate error.

My table structure is bellw:

Table "ax_delivery_info":

Table "ax_party_info":



public function delivery_entry()
{
$this->load->library('grocery_CRUD');
$this->load->library('grocery_crud_categories') ;
$crud = new grocery_CRUD();
$crud->set_relation('party_name','ax_party_info','party_name');
$crud->set_table('ax_delivery_info');

$config = array(
'table_name'=>'ax_delivery_info',
'related_table'=>'ax_party_info',
'sort_field'=>'party_name',
'categories_primary_key'=>'party_code',
'related_title_field'=>'party_name',
'order_by'=>'party_name',

'first_url' => base_url().__CLASS__.'/'.__FUNCTION__,
'segment_name' => 'party_name',
'style' => 'height:24px; width: 200px;',
'text'=>array('all_rows'=>'select category')
);
$categories = new grocery_crud_categories($crud,$config);
$dropdown = $categories->get_dropdown();
$output = $crud->render();
$output->output = $dropdown . $output->output;
$this->crud_output($output);
}

function crud_output($output = null)
{
$data['output'] = $output;
$this->load->view('output', $data);
}


The Error : [attachment=353:err.png]

victor
  • profile picture
  • Member

Posted 14 November 2012 - 07:40 AM

Hi & thanks! The bug is fixed. Download the library again.

tofayelahmed
  • profile picture
  • Member

Posted 14 November 2012 - 08:07 AM

Nice!
Another problem.
When add record an error is shown. [attachment=355:err1.png]

victor
  • profile picture
  • Member

Posted 14 November 2012 - 08:31 AM

tofayelahmed, thanks!
the bug was fixed. Download the fresh version)

tlc033
  • profile picture
  • Member

Posted 01 December 2012 - 23:18 PM

Hi. What about integration this function
$this->get_datetime_input($field_info,$value);
from libraries / grocery_crud.php / ...LINE about 2041 protected function get_datetime_input($field_info,$value) in [b]grocery_crud_categories.php[/b]
To lock like this:
[img]http://s9.postimage.org/vqe0zkfhr/image.png[/img]

victor
  • profile picture
  • Member

Posted 02 December 2012 - 00:03 AM

Show your table structure.

tlc033
  • profile picture
  • Member

Posted 02 December 2012 - 14:34 PM

I can modiify table structure, but i need 2 selectors, 1 CATEGORY, 2 DATA.
My structure is like this:
ID pk int
name varchart
start_time
end_time
category
...
status

victor
  • profile picture
  • Member

Posted 02 December 2012 - 14:42 PM

Are this inputs for the start_date and end_date fields?

tlc033
  • profile picture
  • Member

Posted 02 December 2012 - 14:51 PM

[quote name='victor' timestamp='1354459372' post='4536']
Are this inputs for the start_date and end_date fields?
[/quote]

Yes

Wilman Bhigu
  • profile picture
  • Member

Posted 04 December 2012 - 00:53 AM

Hi Victor, this library is working great. It is simplify my job here. Thank's a lot.

tlc033
  • profile picture
  • Member

Posted 24 December 2012 - 12:51 PM

Hi Victor, how can i use where condition for ex.

'parent_field'=>'parent_id',
'order_by'=>'category_name',
...
'where_condition'=>'some condition for related_table',


THX.

victor
  • profile picture
  • Member

Posted 24 December 2012 - 12:54 PM

try use $crud->where();

victor
  • profile picture
  • Member

Posted 24 December 2012 - 12:57 PM

Really I didn't use this library yet ))). only once.

tlc033
  • profile picture
  • Member

Posted 24 December 2012 - 12:59 PM

Not work $crud->where(); , i try it.

victor
  • profile picture
  • Member

Posted 24 December 2012 - 13:02 PM

you can change the "set_where" method in my library

victor
  • profile picture
  • Member

Posted 24 December 2012 - 13:04 PM



function set_where()
{
if (isset($this->category))
{
if (isset($this->parent_field))
{
$categories = $this->get_child_nodes_r($this->category);
$categories[] = $this->category;
$in = NUll;
foreach ($categories as $item)
$in.= $this->ci->db->escape($item) . ",";

$in = substr($in, 0, -1);
$where = "`$this->table_name`.`" . $this->sort_field . "` IN(" . $in . ")";
$this->grocery_crud_obj->where($where);
}
else
{
$this->grocery_crud_obj->where($this->table_name . '.' . $this->sort_field, $this->category);
}
}
}


this string:
$this->grocery_crud_obj->where($this->table_name . '.' . $this->sort_field, $this->category);

tlc033
  • profile picture
  • Member

Posted 24 December 2012 - 13:09 PM

OK, but it well affecting other...
If i use
'parent_field'=>'parent_id',
it set me parrent_id = 0 but i need parrent_id = 1

I need to view in select only categories how have sub_category