Author Topic: I am using treeModel, but addNode and getChanges are malfunctioning.  (Read 312 times)

tbum

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 11
    • View Profile
Hello, I'm tbum,

I use treeModel to represent the grid.
When I did addNode, I temporarily set the id value to "pq_tmp_~~~".
And after saving is complete.
grid.commit(type:'add',rows:~~);
and the commit worked fine.

but
If addNode is executed once more
When the getChanges function is executed, it tries to save 2 rows including the row saved before addList.
So I ran grid.commit() // no args .

I wonder if writing the code as above is correct programming.

Currently I am using paramquery 8.x. I wonder if it's because of that.

And after I addNode and save. When I tried to add one more node to the just-added node, it was added to the last row of the entire grid, so when I checked it in debug mode, I found that the id of the previously created node was still "pq_tmp_~~~" in the cache.

How can I update both cache and dataModel.data after save?



Quote

const saveChanges = async () => {
  //attempt to save editing cell.
  // debugger;
  if (grid.saveEditCell() === false) {
    return false;
  }
  const orderChanged = setOrderChanges();
  const parentChanged = setParentChanges();
  let isChanged = false;
  if (orderChanged.length > 0) {
    isChanged = true;
  }

  if (grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid) {
    isChanged = true;
    var changes = grid.getChanges({ format: 'raw' });
    console.log(changes);

    // console.log(parentChanged);

    legendData = await request.finances.post('/budgetAccount/saveItem', changes);
    // console.log(legendData);
    // return;
    Object.keys(legendData).map(key => {
      let data = legendData[key];
      if (key === 'add') {
        data.map(item => {
          const rowIndx = item.pq_ri;
          grid.removeClass({
            rowIndx: rowIndx,
            cls: 'new-row',
          });
          // item.budgetIdx = item.budgetIdx.toString();

          grid.updateRow({
            rowIndx: rowIndx,
            newRow: {
              budgetIdx: item.budgetIdx,
              budgetCode: item.budgetCode,
              displayCode: item.displayCode,
            },
            checkEditable: false,
            history: false,
            track: true,
          });
          return {
            budgetIdx: item.budgetIdx,
          };
        });

        console.log(data);

// If the rows value is not entered, the budgetIdx value appears to have been updated in tmp, but it is not actually updated.
        // So after saving, if you try to add a node as a child node of that node, it's like trying to reference a parentId that doesn't exist.
        // misbehavior.
        grid.commit({
          type: key,
          rows: data,
        });

// However, in this case, there is a problem that children such as pq_tmp_0.234234 remain uncommitted. If you call the getChanges function
        // Trying to save one more time, data increases exponentially.
        // Commit one more time to empty.
        grid.commit({
          type: key,
        });
      } else {
        grid.commit({
          type: key,
          rows: data,
        });
      }
    });
  }