Premium support for our pure JavaScript UI components


Post by vasyl obukh »

Hi,
I used this topic as a base viewtopic.php?p=126626 for using a react component as a column editor but faced with many issues where editing mode closes all the time.

Here's the editor component code (the full example is in the attachments):

import React from 'react';

// Defines a simple React cell editor that displays two buttons Yes|No, for editing boolean columns
export default class DemoEditor extends React.Component {
    state = {
        value : []
    };

//region Cell editing interface, required functions

// Should return the value to be applied when editing finishes
getValue() {
    console.log('get value', this.state.value);
    return this.state.value;
}

// React setState is asynchronous so we return Promise which is resolved when setState finishes
setValue(value) {
    console.log('set value', value);
    return new Promise(resolve => this.setState({ value }, () => resolve(value)));
}

// Invalid editors are note allowed to close (unless grid is so configured). Implement this function to handle
// validation of your editor
isValid() {
    // This simple editor is always valid
    return true;
}

// Called when editing starts, to set focus at the desired place in your editor
focus() {}

//endregion

render() {
    return (
      <div
        style={{
            backgroundColor: "white",
            color: "black",
            width: "100%",
            display: "flex",
        }}
      >
          {(this.state.value || []).map(({ id, name, level }) => (
            <div key={id}>
                {name}{level ? `, ${level.name}` : ""}
                <button
                  onClick={() =>
                    this.setValue(
                      // Case #1
                      this.state.value.filter((item) => item.id !== id)
                      // Case #2
                      // this.state.value.slice(0, this.state.value.length - 1)
                    )
                  }
                >
                    X
                </button>
            </div>
          ))}
      </div>
    );
}
}

and task data

{
        "id"             : 12,
        "name"           : "Configure firewall",
        "percentDone"    : 50,
        "startDate"      : "2019-01-14",
        "rollup"         : true,
        "duration"       : 3,
        "endDate"        : "2019-01-17",
        "skills": [
          {
            "id": "s1",
            "name": "Java",
            "level": {
              "id": "sl3",
              "name": "Senior"
            }
          },
          {
            "id": "s2",
            "name": "JavaScript",
            "level": {
              "id": "sl1",
              "name": "Junior"
            }
          },
          {
            "id": "s3",
            "name": "SQL",
            "level": null
          }
        ]
      }
  • Case 1
    By clicking on any delete button while editing the skills cell, the last skill gets removed (it's the only case I found where it doesn't automatically close all the time). If you click on any button except for the last one then editing mode keeps being active. But when you click on the last button editing mode stops and the editor closes. Check attached video #1.

  • Case 2
    By clicking on any delete button while editing the skills cell, the skill that that button was rendered for gets removed. The editing mode should still be active but it always stops and closes the editor. Check attached video #2.

The actual component is more complicated (there's a dropdown to select skills and levels) but at least there I know that dropdown is open and I just return false on "beforeCancelCellEdit" and "beforeFinishCellEdit" events so it's not closing automatically before dropdown is closed. But we need to be able to remove items without opening the dropdown.

Could you please give any suggestions on what is wrong with the code or what I need to do additionally to stop it from autoclosing?

Attachments
Screen Recording 2024-02-28 at 1.17.20 PM.mov
(3.1 MiB) Downloaded 44 times
Screen Recording 2024-02-28 at 1.18.55 PM.mov
(2.55 MiB) Downloaded 37 times
editor-issue.zip
(3.77 MiB) Downloaded 41 times

Post by alex.l »

Hi,

That looks like a bug, we need to investigate it deeply. Link: https://github.com/bryntum/support/issues/8717
Thanks for the report!

All the best,
Alex


Post by ghulam.ghous »

Hi Vasyl,

I have investigated this issue and it turned out that upon each value change, the editor was losing focus and closing. This behavior is inherent to our default settings, where editing is finalized when the editor being blurred or if the user taps outside of it. A similar issue was reported here: https://github.com/bryntum/support/issues/7267.

To address this issue, we have introduced a new configuration option called managedCellEditing on the column in version 5.6.9. Setting this option to false allows manual control over when cell editing should be finalized. So please upgrade to the version 5.6.9 and set this config to false on the column.

config: https://bryntum.com/products/grid/docs/api/Grid/column/Column#config-managedCellEditing
guide: https://bryntum.com/products/grid/docs/guide/Grid/integration/react/guide#custom-cell-editors-with-pickers
our online demo (check datePicker editor): https://bryntum.com/products/grid/examples/frameworks/react-vite/cell-edit/dist/

    {
      field: "skills",
      text: "Skills",
      width: 350,
      align: "center",
      managedCellEditing: false,
      editor: (ref) => <DemoEditor ref={ref} />,
      renderer: ({ value }) => value.map(({ name }) => name).join(", "),
    },

Here is the updated use case:

editor-issue.zip
(3.81 MiB) Downloaded 7 times

Video Clip:

Screen Recording 2024-04-19 at 7.06.31 PM.mov
(1.19 MiB) Downloaded 4 times

Regards,
Ghous


Post Reply