I see you're evaluating our Grid component, and my example is written for Scheduler, but the idea is the same. You can check how it works in Grid MultiRegion demo:
const grid = new Grid({
adopt : 'container',
minHeight : '20em',
features : {
group : false,
sort : false,
columnPicker : false,
contextMenu : {
// implement your own column disabling
processHeaderItems({ column, items }) {
const columns = grid.subGrids[column.region].columns.query(column => column.hideable);
// In case you need to show columns from all regions
//const columns = grid.columns.query(column => column.hideable);
items.push(...columns.map(column => {
return {
text : column.text,
name : column.id,
checked : column.hidden !== true,
onToggle() {
column.hidden = !column.hidden;
}
};
}));
}
}
},
columns : [
{ text : 'First name', field : 'firstName', width : 180, region : 'left' },
{ text : 'Surname', field : 'surName', width : 180, region : 'left' },
{ text : 'Age', field : 'age', width : 180, region : 'middle' },
{ text : 'Score', field : 'score', width : 180, region : 'middle' },
{ text : 'Rank', field : 'rank', width : 180, region : 'middle' },
{ text : 'Percent', field : 'percent', width : 180, region : 'middle' },
{ text : 'Rating', field : 'rating', width : 180, region : 'middle' },
{ text : 'City', field : 'city', width : 180, region : 'right' },
{ text : 'Done', field : 'done', width : 180, region : 'right' }
].map(item => Object.assign(item, { draggable : false })), // configured all items as not draggable
If you don't need "Move column to ..." items, but want to keep columns draggable, you can simple remove those items in processHeaderItems handler.
Awesome ,thank you for the super in depth answer! I got the column stuff working with your examples, however, I am running into another wall I believe. Is there anyway to keep the header functionality for sorting and dragging but keep it out of the contextMenu or is that also going to need some config finesse? Also, is it possible to lock columns to their respective section/subgraph/region while still maintaining dragging? Thanks again for any info.
Is there anyway to keep the header functionality for sorting and dragging but keep it out of the contextMenu or is that also going to need some config finesse?
There is no feature config to prevent adding to the header context menu. You can keep the feature enabled but simply find and remove sorting items from the "items" array in processHeaderItems.
Also, is it possible to lock columns to their respective section/subgraph/region while still maintaining dragging?
Thanks for the super detailed responses btw, you've been super helpful. I just learned of some new requirements and I was having a bit of trouble regarding listeners. Sort is expected to happen on double click, I swore I thought I saw a listener around double click, and is there an easy way to invoke the columns defined sorter via an event listener rather than using native? I tried adding listeners under the column like so
Secondly,
They want the contextMenu to only show up when you click the 3 dot icon on the right, is this in the realm of possibility? and if not is it possible to make it appear on single left click for only this header?
Screen Shot 2020-06-11 at 12.27.15 PM.png (3.92 KiB) Viewed 2098 times
Third unrelated thing i'm seeing is when I scroll down on the page at all when I drag a column, the dragged column is floating (it looks like the header being dragged is locked in a specific Y coord, it's position seems relative to the height of the scroll. Is this a known bug or is something going on with my implementation?
Screen Shot 2020-06-11 at 12.29.51 PM.png (7.8 KiB) Viewed 2098 times
The number of clicks on the column header to trigger the sorting is not currently configurable. You could write your own feature (extending the existing Sort feature) to sort on dblclick. What you might have seen in docs on dblclick is that it is the default trigger event for cell edit feature.
Your listeners on columns are ignored because you pass them as item of the array when they're understood as data. If you want some listeners on https://bryntum.com/docs/grid/#Grid/data/ColumnStore you must pass them as:
columns : {
data : [
{ text : 'First name', field : 'firstName', width : 180, region : 'left' }, .....
],
listeners : {
beforeUpdate({ record, changes }) {
// constrain columns to their regions
if (changes && changes.region && changes.region !== record.region) {
return false;
}
}
}
},
Mind please that columns is a ColumnStore so it doesn't fire UI events.