{Header}

Hierarchical Category & Directory Maintenance

Description

This example shows a sample implementation of a system that can be used to manage hierarchical data. In this case, it is the list of categories that are later used in the directory.

Usage

  1. Navigate to the directory level that you want to update.
  2. To add a new category: enter the 'Category Name' and click the 'Add' button. The new category will be added at the current level. If you are at the root level then a new root category will be created.
    To edit a category: click the 'Edit' link next to the category, change the value in the 'Category Name' field and then click the 'Submit' button.

Steps to recreate

  1. Create a new page and create a table with 2 columns.
  2. In the left column of the table, use the Directory Builder to create the directory with the path based on the directory_categories table.  In the 2nd step of the Builder leave the Root Category identifier field empty and specify Number of Columns as "1 ".
  3. Switch to HTML mode and add a Link inside the "Category" block before "{CategoryLink}" to create a link for editing the categories.  
  4. Set the current page as the value of the new link's Href Source property and then also in the Href Source property add a Link Parameter with the following values: Data Source Type = DataSource Column, Parameter Source = cat_category_id and Parameter name = edit_id. Set the Default property of the Link to Edit and add parent_id into the Remove Parameters property.
  5. Add another Link link inside the "SubCategory" block before {SubCategoryLink} to create a link for editing the subcategories.
  6. Set the current page as the value of the link's Href Source property and then add a Link Parameter with the following values: Data Source Type = DataSource Column, Parameter Source = sub_category_id and Parameter name = edit_id.
    Add another Link Parameter with the following property values: Data Source Type = DataSource Column, Parameter Source = cat_category_id  and Parameter name = parent_id. Set the Default property of the Link to Edit.
  7. Switch back to the Design mode and add the text edit_id;parent_id into the Remove Parameters property of the following Links: "PathCategory" within the Path component, "CategoryLink", "SubCategoryLink" and "More" within the Directory component.
  8. Add the text ;edit_id;parent_id to category_id into the Remove Parameters property of the "Main" link within the Path component.
  9. In the right column of the table, use the Record Builder to create the record form based on the directory_categories table and containing two fields: category_name and category_id_parent. In the 2nd step of the builder specify that the field category_id_parent   is of "Hidden" type.
  10. Open the "Data Source" dialog of the record form and double-click on the Where parameter that is shown as "category_id = {category_id}", then change the "Parameter source" from category_id to edit_id.
  11. Enter edit_id;parent_id in the Remove Parameters property of the record form.
  12. Copy or add the appropriate programming code in the record's Before Show event, as provided with the example. You may also need to modify the code to match your form names, or rename the Directory and Record forms on the page to have the same names as those in the example.
  13. Make cosmetic changes as needed, by modifying the text, captions and the layout within the HTML.

Database Tables used

Database: Internet

Tables: directory_categories

Programming Notes

The record form's  Before Show event was used to automatically set the parent category id of the newly created or modified category.