The table columnCount

That was just because you didn’t want to.

To me it seems plausible that if the user deletes a column one might want to remove the corresponding column definition. But one doesn’t have to design your app that way – maybe some apps do want their columns to be “sticky”. That’s not for us to decide.

But it seems clear that you don’t want that column information to remain, so it seems clear to me that you do want to call removeColumnDefinition,

My goal is just smoothly add/remove columns and rows. if it is a editable table, must have those function I think.
I am not “don’t want that column information to remain”, just not to delete it, it not work correctly, OK any way, so we use it again to try.

when deleting the order is, should delete column from the itemArray first or removeColumnDefinition at the first?
and other question is there a best way to refresh the selectionAdornment? when add column the resize marker dose not appear you know.

They’re independent, so I believe either order can work. But I haven’t tried it.

Call Part.updateAdornments?

the deleting order I will try it,

the second question, Part.updateAdornments not effect, maybe because in the
ColumnResizingTool.js has this code

      var adornment = part.findAdornment(this.name);
      if (adornment === null) {
        adornment = this.makeAdornment(table);
        part.addAdornment(this.name, adornment);
      }

may I rewrite it to every time make a new adornment like this

      let adornment = this.makeAdornment(table);
      part.addAdornment(this.name, adornment);

? not memory leak ?

Ah, yes, the tool’s updating of the Adornment doesn’t add or remove any resizing handles – it just updates their positions. OK, do this then:

    . . .
    myDiagram.commitTransaction("addColumn");
    n.clearAdornments();
    n.updateAdornments();

this works, thank you,

back to the original problem, because delete column always tricky, I got a idea to always delete last column, of course before delete move all data once. in the first glance it seems work, i did’t test all.

row deletion has same problem.

and applyIncrementalJson problem still remains.

is there any event or hook when applyIncrementalJson? , if has i can use it to call removeColumnDefinition or something.

Isn’t your code calling it?

I mean is there any event when I apply applyIncrementalJson

Always delete last column, has a problem with UndoManager
my shift loop is like this

for (let idx = deleteCol; idx < coldefs.length-1; idx++) {
	coldefs[idx].attr = coldefs[idx+1].attr;
	coldefs[idx].text = coldefs[idx+1].text;
	coldefs[idx].cwidth = coldefs[idx+1].cwidth;
}

but the UndoManager don’t remember before the loop , instead it remember the after loop, of course I do this in same transaction.

It means the UndoManager doesn’t remember the before the shift, it does remember after the shift.

Always make property changes to data by calling Model.set.

Also, I don’t think you should be shifting the data in your column descriptors. I wonder if what you are doing is causing confusion.

Yes it is, almost same time i also figure out it thank you.

for (let idx = deleteCol; idx < coldefs.length-1; idx++) {
	model.set(coldefs[idx], "attr", coldefs[idx+1].attr);
	model.set(coldefs[idx], "text", coldefs[idx+1].text);
	model.set(coldefs[idx], "cwidth", coldefs[idx+1].cwidth);
}

“always delete last” is not so efficient, it seams work. still remains row has same problem and applyIncrementalJson problem.

ignore the 0 width column has another problem, accidentally drag the column size to 0, then no way to take back the column, it disappear!

and again, the root problem is even deleting column last column, columnCount not changed!!

this time the undoManager, don’t replay column width,

Screen Recording 2021-08-21 at 8.29.10 AM

how to reproduce:

  1. add 3 columns
  2. resize the second added column
  3. press the crtl+z many times undo all
  4. press the crtl+y many times redo all

see the second added column width not be replay. it not remembered.
but in the node’s data the width is exist.

That’s a bug. We’ll fix it in 2.1.49, which should become available next week sometime.

Thank you, walter, and my progress is, that, always delete the last
columns or rows is good for me. because, in this way we not need to change column number or row number so the table not behave tricky. this way is not so efficient, but i think in the gojs table no one to edit thousand of lines.
right now i can add delete and resize row col smoothly. :) even not well tested yet. you know I am a good tester :)

applyIncrementalJson problem still remains.

After adding some delete the coldef or rowdef call after applyIncrementalJson then, now worked. not efficient just somehow worked. so I will close this thread, waiting v2.1.49 ,and, thank you Walter for long session.