Treemenu - Expand First Item

Hello,

I have a tree menu and I would like to expand only the first item in the tree when the menu loads.

I have tried adding javascript code to the menu’s OnLoad event but have had no success with this so far.

Has anyone managed to achieve this?

Thanks,

Mike

You ca do it, using macros like sc_appmenu_create, sc_appmenu_add_item.

Thanks Alvagar,

I’m already using sc_appmenu_create() to dynamically create my menu items, but the only options that I have are to set Expand Items On or Off in the treemenu settings.

What I would like is to expand only the first node in the tree menu.

If anyone has any ideas as to how this could be achieved I’d appreciate it.

Mike

your menu is dynamic? Or have fixed items?

Do you have a script for create your items?

Hi Alvagar,

My menu is created via a script called from the OnApplicationInit event.

Regards,

Mike

Can show me your script. So i can help you.

Hi Alvagar,

Below is my menu code…

Ideally, I’d like the root item (item_0) to be expanded when the menu loads, but all child nodes closed.

Regards,

Mike

sc_appmenu_reset(treemenu_branch);
sc_appmenu_create(treemenu_branch);

// Root.
sc_appmenu_add_item(treemenu_branch, “item_0”, , $root_menu, , , , 'Upsilon-ERP - ’ . $root_menu, );

// Customers.
sc_appmenu_add_item(treemenu_branch, ‘item_1’, ‘item_0’, ‘Sales’, ‘’, , ‘’, ‘Sales Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_2’, ‘item_1’, ‘Customers’, ‘grid_view_customers’, , ‘’, ‘Customers’, ‘_self’);
//sc_appmenu_add_item(treemenu_branch, ‘item_3’, ‘item_1’, ‘Contacts’, ‘grid_view_customers_contacts’, , ‘’, ‘Customer Contacts’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_4’, ‘item_1’, ‘Analysis Codes’, ‘grid_view_customers_analysis_codes’, , ‘’, ‘Customer Analysis Codes’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_5’, ‘item_1’, ‘Business Types’, ‘grid_view_customers_business_types’, , ‘’, ‘Customer Business Types’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_6’, ‘item_1’, ‘Categories’, ‘grid_view_customers_categories’, , ‘’, ‘Customer Categories’, ‘_self’);

// Customer reports.
sc_appmenu_add_item(treemenu_branch, ‘item_7’, ‘item_1’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Sales Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_8’, ‘item_7’, ‘List Customers’, ‘control_list_customers_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Customers Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_9’, ‘item_7’, ‘Analysis Codes’, ‘control_list_analysis_codes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Analysis Codes Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_10’, ‘item_7’, ‘Business Types’, ‘control_list_business_types_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Business Types Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_11’, ‘item_7’, ‘Categories’, ‘control_list_customer_categories_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Categories Report’, );

// Suppliers.
sc_appmenu_add_item(treemenu_branch, ‘item_101’, ‘item_0’, ‘Purchase’, ‘’, , ‘’, ‘Purchase Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_102’, ‘item_101’, ‘Suppliers’, ‘grid_view_suppliers’, , ‘’, ‘Suppliers’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_103’, ‘item_101’, ‘ISO Ratings’, ‘grid_view_suppliers_iso_ratings’, , ‘’, ‘Supplier ISO Ratings’, ‘_self’);

// Supplier reports.
sc_appmenu_add_item(treemenu_branch, ‘item_104’, ‘item_101’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Purchase Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_105’, ‘item_104’, ‘List Suppliers’, ‘control_list_suppliers_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Suppliers Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_106’, ‘item_104’, ‘ISO Ratings’, ‘control_list_supplier_iso_ratings_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Supplier ISO Ratings Report’, );

// Products.
sc_appmenu_add_item(treemenu_branch, ‘item_201’, ‘item_0’, ‘Stock Control’, ‘’, , ‘’, ‘Stock Control Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_202’, ‘item_201’, ‘Products’, ‘grid_view_products’, , ‘’, ‘Products’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_203’, ‘item_201’, ‘Product Categories’, ‘grid_view_products_categories’, , ‘’, ‘Product Categories’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_204’, ‘item_201’, ‘Adjustments In’, ‘control_product_adjustments_in’, , ‘’, ‘Product Adjustments In’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_205’, ‘item_201’, ‘Adjustments Out’, ‘control_product_adjustments_out’, , ‘’, ‘Product Adjustments Out’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_206’, ‘item_201’, ‘Adjustments Level’, ‘control_adjust_product_level’, , ‘’, ‘Adjustments Product Level’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_207’, ‘item_201’, ‘Quarantine In’, ‘control_product_quarantine_in’, , ‘’, ‘Quarantine Products In’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_208’, ‘item_201’, ‘Quarantine Out’, ‘control_product_quarantine_out’, , ‘’, ‘Quarantine Products Out’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_209’, ‘item_201’, ‘Stock Take’, ‘grid_products_stock_take’, , ‘’, ‘Stock Take’, ‘_self’);

// Stock Control reports.
sc_appmenu_add_item(treemenu_branch, ‘item_210’, ‘item_201’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Stock Control Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_211’, ‘item_210’, ‘List Products’, ‘control_list_products_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Products Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_212’, ‘item_210’, ‘Product Categories’, ‘control_list_product_categories_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Product Categories Report’, );

// Quotations Module.
sc_appmenu_add_item(treemenu_branch, ‘item_301’, “item_0”, ‘Quotations’, ‘’, , ‘’, ‘Quotations Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_302’, “item_301”, ‘Quotations’, ‘grid_view_quotations’, , ‘’, ‘Quotations’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_303’, “item_301”, ‘Lead Types’, ‘grid_quotations_lead_types’, , ‘’, ‘Quotation Lead Types’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_304’, “item_301”, ‘Cancellation Types’, ‘grid_quotations_cancellation_types’, , ‘’, ‘Quotation Cancellation Types’, ‘_self’);

// Quotations reports.
sc_appmenu_add_item(treemenu_branch, ‘item_305’, ‘item_301’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Quotation Reports Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_306’, ‘item_305’, ‘List Quotations’, ‘control_list_quotations_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Quotations Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_307’, ‘item_305’, ‘Print Quotes’, ‘control_print_quotations_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Quotes Report’, );

// Sales Orders.
sc_appmenu_add_item(treemenu_branch, ‘item_401’, “item_0”, ‘Sales Orders’, ‘’, , ‘’, ‘Sales Orders Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_402’, “item_401”, ‘Sales Orders’, ‘grid_view_sales_orders’, , ‘’, ‘Sales Orders’, ‘_self’);

// Sales Order reports.
sc_appmenu_add_item(treemenu_branch, ‘item_403’, ‘item_401’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Sales Order Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_404’, ‘item_403’, ‘List Sales Orders’, ‘control_list_sales_orders_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Sales Orders Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_405’, ‘item_403’, ‘Print Acceptance Notes’, ‘control_print_order_acceptance_notes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Acceptance Notes Report’, );

// Invoices.
sc_appmenu_add_item(treemenu_branch, ‘item_501’, “item_0”, ‘Invoices’, ‘’, , ‘’, ‘Invoices Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_502’, “item_501”, ‘Invoices’, ‘grid_view_invoices’, , ‘’, ‘Invoices’, ‘_self’);

// Invoice reports.
sc_appmenu_add_item(treemenu_branch, ‘item_503’, ‘item_501’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Invoice Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_504’, ‘item_503’, ‘List Invoices’, ‘control_list_invoices_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Invoices Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_505’, ‘item_503’, ‘Print Invoices’, ‘control_print_invoices_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Invoices Report’, );

// Pro-Forma Invoices.
sc_appmenu_add_item(treemenu_branch, ‘item_601’, “item_0”, ‘Pro-Forma Invoices’, ‘’, , ‘’, ‘Pro-Forma Invoices Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_602’, “item_601”, ‘Pro-Forma Invoices’, ‘grid_view_pro_forma_invoices’, , ‘’, ‘Pro-Forma Invoices’, ‘_self’);

// Pro-Forma Invoice reports.
sc_appmenu_add_item(treemenu_branch, ‘item_603’, ‘item_601’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Pro-Forma Invoice Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_604’, ‘item_603’, ‘List Pro-Forma Invoices’, ‘control_list_pro_forma_invoices_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Pro-Forma Invoices Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_605’, ‘item_603’, ‘Print Pro-Forma Invoices’, ‘control_print_pro_forma_invoices_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Pro-Forma Invoices Report’, );

// Credit Notes.
sc_appmenu_add_item(treemenu_branch, ‘item_701’, “item_0”, ‘Credit Notes’, ‘’, , ‘’, ‘Credit Notes Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_702’, “item_701”, ‘Credit Notes’, ‘grid_view_credit_notes’, , ‘’, ‘Credit Notes’, ‘_self’);

// Credit Notes reports.
sc_appmenu_add_item(treemenu_branch, ‘item_703’, ‘item_701’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Credit Notes Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_704’, ‘item_703’, ‘List Credit Notes’, ‘control_list_credit_notes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Credit Notes Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_705’, ‘item_703’, ‘Print Credit Notes’, ‘control_print_credit_notes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Credit Notes Report’, );

// Works Orders.
sc_appmenu_add_item(treemenu_branch, ‘item_801’, “item_0”, ‘Works Orders’, ‘’, , ‘’, ‘Works Orders Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_802’, “item_801”, ‘Works Orders’, ‘grid_view_works_orders’, , ‘’, ‘Works Orders’, ‘_self’);

// Purchase Orders.
sc_appmenu_add_item(treemenu_branch, ‘item_901’, “item_0”, ‘Purchase Orders’, ‘’, , ‘’, ‘Purchase Orders Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_902’, “item_901”, ‘Purchase Orders’, ‘grid_view_purchase_orders’, , ‘’, ‘Purchase Orders’, ‘_self’);

// Purchase Order Reports.
sc_appmenu_add_item(treemenu_branch, ‘item_903’, ‘item_901’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Purchase Orders Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_904’, ‘item_903’, ‘List Purchase Orders’, ‘control_list_purchase_orders_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Purchase Orders Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_905’, ‘item_903’, ‘PrintPurchase Orders’, ‘control_print_purchase_orders_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Purchase Orders Report’, );

// Debit Notes.
sc_appmenu_add_item(treemenu_branch, ‘item_0101’, “item_0”, ‘Debit Notes’, ‘’, , ‘’, ‘Debit Notes Module’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_0102’, “item_0101”, ‘Debit Notes’, ‘grid_view_debit_notes’, , ‘’, ‘Debit Notes’, ‘_self’);
sc_appmenu_add_item(treemenu_branch, ‘item_0103’, “item_0101”, ‘Reason Codes’, ‘grid_debit_notes_reason_codes’, , ‘’, ‘Reason Codes’, ‘_self’);

// Debit Note Reports.
sc_appmenu_add_item(treemenu_branch, ‘item_0104’, ‘item_0101’, ‘Reports’, , , ‘…/…/_lib/img/sys__NM__menu_img__NM__reports.png’, ‘Debit Notes Reports’, );
sc_appmenu_add_item(treemenu_branch, ‘item_0105’, ‘item_0104’, ‘List Debit Notes’, ‘control_list_debit_notes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Debit Notes Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_0106’, ‘item_0104’, ‘List Reason Codes’, ‘control_list_reason_codes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘List Reason Codes Report’, );
sc_appmenu_add_item(treemenu_branch, ‘item_0107’, ‘item_0104’, ‘Print Debit Notes’, ‘control_print_debit_notes_report’, , ‘…/…/_lib/img/sys__NM__menu_img__NM__individual_report.png’, ‘Print Debit Notes Report’, );

I can see In settings, set “Expand Items”. (But it works for all items).
I think must must try with javascript.

Hi Mikew,
why not two menus, one with the first node, and the second with all the nodes, and an if, it will take a little place in the menu code, but I use it with dynamic menus more room in the code, but less of a puzzle for the solution

Hi Guys,

Thanks for your input.

As Alvagar says it really is the javascript code that I need to expand only the first item (item_0) in the menu. I’ve tried a few things in this regard over the last few weeks, but nothing has worked so far.

I’ll keep trying, but if anybody has managed to do this I would appreciate some pointers.

Cheers,

Mike

the problem lies in the management of the menus directly in the app menu,
you have to manage the items in a table and retrieve them according to the user,
I solved this kind of problem by creating an item table with rights, etc,
I created a form to assign either groups or users a menu of their own, then a foreach in an app menu and everything works properly, in fact if the menu with all items is corrupted, the whole menu will be problematic , by managing the items in a table we always recover them during a crash or a modification of the RAD,
good continuation,