Jump to content


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

categories dropdown adjacency list

  • Please log in to reply
26 replies to this topic

#1 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 10 November 2012 - 12:05 AM

Hi all!
I created a library which adds a drop-down menu of categories into the grid header.
___________________________________________
Download here:
Attached File  grocery_crud_categories.php   5.35K   1103 downloads
updated 14/11/2012
___________________________________________

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.
And most importantly, this library do not require changes to the view!
a.jpg b.jpg

How to use:

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);
}

The second method of integrate.
$categories = new grocery_crud_categories($crud,$config);
$dropdown = $categories->get_dropdown();

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

Config:

1)* 'table_name'=>'adj_goods',
2)* 'related_table'=>'adj_category',
3)* 'sort_field'=>'goods_category',
4)* 'categories_primary_key'=>'category_id',
5)* 'related_title_field'=>'category_name',
6) 'parent_field'=>'parent_id', - if you use a single-level list set this param as "false",


click -> how.jpg

7) 'order_by'=>'category_name' - lets you set an ORDER BY clause. Example: 'order_by'=>"position DESC,name ASC"

8)* 'first_url' => base_url().__CLASS__.'/'.__FUNCTION__ - base url for the links

9)'segment_name' = 'category'; - segment name. http://localhost/examples/goods/category/7


10) 'style' => 'height:24px; width: 200px;' - you can use your styles for this menu
11) 'class'=>'your_class' - you can use a class too

12) 'text'=>array('all_rows'=>'all categories') - text for the first element of list ( "<option>all categories</option>")


* - element is required.

-----------------------------------

I created this library for the flexigrid theme, but it works with the datatable (you can modify the code as you like ;) ).

P.S: If you have suggestions for improving the library, I will be glad to hear. :)

P.S.S. Code can contain some bugs :ph34r:. If you find a bug - report, please.

Sorry, my English is bad :(.


Edited by victor, 02 December 2012 - 12:59 PM.


#2 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 10 November 2012 - 07:08 PM

10+++ THX. I well test it.

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#3 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 12 November 2012 - 04:54 PM

Today the library will be updated a little :)

#4 tofayelahmed

tofayelahmed

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

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 : err.png

Attached Thumbnails

  • table1.png
  • table2.png


#5 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 14 November 2012 - 07:40 AM

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

#6 tofayelahmed

tofayelahmed

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 14 November 2012 - 08:07 AM

Nice!
Another problem.
When add record an error is shown. err1.png

#7 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 14 November 2012 - 08:31 AM

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

#8 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 01 December 2012 - 11: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 grocery_crud_categories.php
To lock like this:
Posted Image

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#9 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 02 December 2012 - 12:03 AM

Show your table structure.

#10 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 02 December 2012 - 02: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

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#11 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 02 December 2012 - 02:42 PM

Are this inputs for the start_date and end_date fields?

#12 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 02 December 2012 - 02:51 PM

Are this inputs for the start_date and end_date fields?


Yes

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#13 Wilman Bhigu

Wilman Bhigu

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 December 2012 - 12:53 AM

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

#14 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

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.

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#15 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 12:54 PM

try use $crud->where();

#16 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 12:57 PM

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

#17 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 24 December 2012 - 12:59 PM

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

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 


#18 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 01:02 PM

you can change the "set_where" method in my library

#19 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 01: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);


#20 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationChisinau

Posted 24 December 2012 - 01: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

We are a web company from Republic of Moldova and offers services as, web design, web development, eCommerce, online marketing and advertising, consulting and web optimization, search engine optimization (SEO) and social media optimization (SMO), branding and rebranding.

 

          logo_small.png  

                         elitiv.com  

                  

 

 






Also tagged with one or more of these keywords: categories, dropdown, adjacency list

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users