⚠ 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 forum is read-only and soon will be archived. ⚠


Category checkbox tree

category checkbox tree

  • Please log in to reply
3 replies to this topic

#1 qwop

qwop

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 03 July 2013 - 02: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.co...nateCheckboxes/ ).

 

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!



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

Posted 04 July 2013 - 08:18 AM

Hello 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!



#3 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 04 July 2013 - 08:47 AM

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

#4 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

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 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.







Also tagged with one or more of these keywords: category, checkbox, tree

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users