⚠ 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

Category checkbox tree



qwop

qwop
  • profile picture
  • Member

Posted 03 July 2013 - 14:34 PM

Hello,

 

I have following db structure:

CREATE TABLE `Category` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ParentID` int(11) NOT NULL,
  `Name` varchar(30) NOT NULL,
  PRIMARY KEY (`ID`)
)

CREATE TABLE `Post` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Title` varchar(30) NOT NULL,
  `Content` text NOT NULL,
  PRIMARY KEY (`ID`)
)

CREATE TABLE `PostCategory` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `PostID` int(11) NOT NULL,
  `CategoryID` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
)

And I use this in my controller:

$crud->set_relation_n_n('Category', 'PostCategory', 'Category', 'PostID', 'CategoryID', 'Name');

Everything is working fine, but I don't like the way multiselect field displays categories, so I want to create checkbox tree with parent and child categories (something like this: http://css-tricks.com/examples/IndeterminateCheckboxes/ ).

 

So the question is, what would be the best way to create such custom field and how to make it work with grocery crud?

 

Thanks!


davidoster

davidoster
  • profile picture
  • Member

Posted 04 July 2013 - 08:18 AM

Hello [member=qwop] and welcome to the forums.

Well here you have two (2) issues actually to deal with.

1. How you will visually display the parent / child categories (maybe with this CSS you posted)

2. How will you save this information of parent / child that the user could select, e.g.

 

Parent 1      X

 |_Child 1    

 |_Child 2    

Parent 2     X

Parent 3

 |_Child 1   X

 |_Child 2

 |_Child 3

 |_Child 4   X

 

On this example the user selects Parent1 as a top category, this means and everything under, also he selects Parent 2 and then from Parent 3, Child 1 and Child 4.

 

No matter what kind of control you are going to use you need, either before dislaying this tree or just before inserting this data to the database, to uniquely distinguish these user selections.

This distinquisement will tell you what kind of control you are going to use.

At that point you can come back here and let us know that this is the one you want to be using and ask on this forum how this can be integrated with Grocery CRUD.

 

So the sort answer is: Plan the way you want this feature implemented and then get some help how this can be integrated to GC.

It's too theretical the question because I can think at least 4 different ways of doing it right now and these have nothing to do with Grocery CRUD!


victor

victor
  • profile picture
  • Member

Posted 04 July 2013 - 08:47 AM

you can use callback_field function to make that. it's not very difficult.

davidoster

davidoster
  • profile picture
  • Member

Posted 04 July 2013 - 09:52 AM

you can use callback_field function to make that. it's not very difficult.

 

With categories and subcategories? Hmmm, you must have something in your mind [member=Victor] that I can't think of right now.

I think it's a bit difficult to have all these, along with subcategories stored on a single field.

It can be done but not that easily, I think.