Group by Column - outline.organize

Here is a simple plugin action (click the disclosure triangle) to organize a multicolumn outline by values in a chosen column. It will present the column titles to pick from a menu.

Plugin Source Code
/*{
	"type": "action",
	"targets": ["omnioutliner"],
	"author": "SG3",
	"identifier": "com.sg3.Column_Group",
	"version": "0.2",
	"description": "Organizes outline by grouping on values in a chosen column",
	"label": "Group on Column",
	"shortLabel": "Group on Column"
}*/

(() => {

	const action = new PlugIn.Action((selection, sender) => {
		// action code
	
		const 
	    	colTitles=columns.map(c => c.title).slice(3,columns.length),
	          // slice to skip Status, Note, Topic columns
	            
			formPrompt =  'Group on values in which column?\n',
	 		buttonTitle = 'OK',
			    
			form = new Form(),
		    	
		  	popup = new Form.Field.Option(
		    	'menu',       	 	// form values key
		        'Column',      		// field label
		         colTitles,    		// objects to display in menu
		         null,         		// custom menu item titles
		         colTitles[0]  		// default selection
		     );	
			     
			form.addField(popup);
		
			colTitles && colTitles.length ? 
			   	form.show(formPrompt, buttonTitle).then(form => {
		      	document.outline.organize(
				rootItem.leaves,	 // items to organize
				[columns.byTitle(form.values['menu'])],   // by which col
				rootItem,       	 // move to this item
				true             	 // remove any empty items
    			 )
			})
	
			: new Alert("Too few columns","Add columns for grouping").show();
	});

	action.validate = (selection, sender) => {
		// validation code

		return true
	};
	
	return action;
	
})();

Save in file with .omnijs extension, go to Automation > Configure > Plug-Ins and drag onto the panel.

See ‘Organize Items’ section here. A sample multicolumn outline is available there for download.

To change the grouping just pick the action again from the Automation menu.

However, I don’t know how to “flatten” the outline the way one can do manually by command-a, option-command-u, followed by delete to remove the selected empty rows (not possible without a keyboard on iPadOS).

Would much appreciate suggestions on a simple action to “flatten” (return to original ungrouped state, order unimportant).

On ways to “flatten” outline see @Draft8 suggestions in this thread.