Skip to content

Commit

Permalink
Changing new items are inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
rugoncalves committed Jul 23, 2024
1 parent 3d20a6a commit 26c42fc
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Providers/DataGrid/Wijmo/Features/ContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,24 @@ namespace Providers.DataGrid.Wijmo.Feature {
menuItem.parentMenuItemId = this._getMenuParentId(menuItem.uniqueId);

//Define menu item's order
menuItem.order = this._defineMenuItemOrder(menuItem.uniqueId);
const menuItemOrder = this._defineMenuItemOrder(menuItem.uniqueId);

//If this menuItem is rootItem, means has no parent menu item
if (menuItem.isRootItem) {
this._rootMenuItems.push(menuItem);
}
//Otherwise find its parent and save it as a child
else {
this._menuItems.get(menuItem.parentMenuItemId).items.push(menuItem);
//If it is a root item, push it to the rootMenuItems array.
//Otherwise, get the correct array.
const arrayItem = menuItem.isRootItem
? this._rootMenuItems
: this._menuItems.get(menuItem.parentMenuItemId).items;

//Check if it is the last item, if so, push it to the end of the array.
//Otherwise, insert it in the correct position.
const isLastItem = menuItemOrder === arrayItem.length;

if (isLastItem) {
arrayItem.push(menuItem);
} else {
arrayItem.splice(menuItemOrder, 0, menuItem);
}

//Sort menu by order - Usefull when the developer inserts a IF statement hiding/showing elements
this._sortMenuItems(this._rootMenuItems);
//If the menu is opening, let's refresh the itemsSource
if (this._isOpening) {
this._provider.itemsSource.refresh();
Expand Down

0 comments on commit 26c42fc

Please sign in to comment.