Shift cells right

Tags: #<Tag:0x00007f13603972c0>

Hello,

I’d like to add a new option to my context menu for shifting cells right. Same feature as in MS Excel actually. :slight_smile:

I played a bit with the alter method and the insert_col action but it inserts one or many columns to all the rows, and not the selected ones.

Did I miss something ?

Thanks for your help.
Caroline

It looks like the populateFromArray method can do the job… Just need to know how to handle it to insert empty cells and shift right the selected cells.

@aleksandra_budnik : if you have an example in fiddle, it would be great ! :slight_smile:

Hey Caroline!

Should it be something like this?

Exactly !

I’m currently using :

const startvisRowIdx = hotInstance.getSelectedLast()[0];
const startColIdx = hotInstance.getSelectedLast()[1];
const endVisRowIdx = hotInstance.getSelectedLast()[2];
const endColIdx = hotInstance.getSelectedLast()[3];

hotInstance.populateFromArray(startvisRowIdx, startColIdx, [['']], endVisRowIdx, endColIdx, undefined, 'shift_right');

But it doesn’t work when it’s used in conjonction with the Trim Rows plugin : empty cells are properly inserted but shifted cells are the ones based on visual indexes and not real indexes. I thought the new version 8 beta would have solved these index issues.

Have you considered copying the cells? Just get the data via getCopyableData loop on the selected cells. The new column will apear automatically.
Then at the end you delete the content of the C5:C7 (our iamge above).

Ouch, it looks more complicated as it’s like re-defining the whole shift action (copy the selected cells + move the unselected cells + paste + delete the original cells to fake the right shift). While the populateArrayFrom does the job… most of the time. :smiley:

There’s a tremendous improvement in terms of index calculations with your latest version 8-beta, but it seeems buggy when it’s used with the Trim Rows plugin (which is mandatory in my project). Therefore I copied the code of populateArrayFrom into my own project and will debug it soon.

Can you share some details? We’re planning to publish beta as stable version in January.

I guess that we can close this topic as there are no updates.

However, please check the updates on new versions and if there’s anything you need feel free to open a new topic.