Column Template Causes Crash

I am using query builder and creating the columns with templates. The templates cause a crash when trying to change the value. The column itself has field, label, operator, and type values as well as the template. Is there some kind of prop that I need to use to get the template function working? I'm using https://ej2.syncfusion.com/react/documentation/query-builder/templates/#using-template to create the template, but I'm still getting these errors. The only time I get this error is when I try to capture the new rule values in the ruleChange or change prop for QueryBuilderComponent.


8 Replies

YA YuvanShankar Arunagiri Syncfusion Team August 8, 2022 06:34 AM UTC

Hi Juliet,


We are unable to replicate the issue in our end. We have prepared the sample based on your requirement. Please refer the below sample link.

Sample link: https://stackblitz.com/edit/react-xstvmz?file=index.js

If you still facing the issue, please share the below details.


  • Share the issue reproducible sample or replicate the issue in our sample.

  • Share the video demonstration of issue replicable.


Please provide the above requested information, based on that we will check and provide you a better solution quickly.



Regards,

YuvanShankar A



JK Juliet King August 8, 2022 01:43 PM UTC

Hello, the issue that I'm having is with Template not ruleTemplate. Here is an example of the code that I am using.


function HomeScreen() {
  const [state, setState] = React.useState({});

  console.log(state);

  return (
    <PEQueryBuilder
      id="home-query-builder"
      value={state}
      onChange={({ value }) => setState(value)}
    />
  );
}


function PEQueryBuilder({ id = "queryBuilder", value, onChange, ...props }) {
  const ref = React.useRef();

  function handleRuleChange(args) {
    if (ref.current) {
      onChange({ value: ref.current.getRules() });
    }
  }

  return (
    <Box>
      <QueryBuilderComponent
        ref={ref}
        id={id}
        dataSource={dataSource}
        rule={!value || typeof value !== "object" ? {} : value}
        change={handleRuleChange}
        sortDirection="Ascending"
        {...props}
      >
        <ColumnsDirective>
          <ColumnDirective field="1001" label="State" type="string" />
          <ColumnDirective field="1002" label="Creation Date" type="date" />
          <ColumnDirective
            field="1003"
            label="Accounting Month"
            type="string"
            template={(args) => <Template queryBuilderId={id} {...args} />}
          />
          <ColumnDirective field="1004" label="Export Date" type="date" />
        </ColumnsDirective>
      </QueryBuilderComponent>
    </Box>
  );
}


function Template({ queryBuilderId, values, ruleID, ...props }) {
  const [openModal, setOpenModal] = React.useState(false);
  const inputRef = React.useRef();
  const queryRef = React.useRef(
    getComponent(document.getElementById(queryBuilderId), "query-builder")
  );

  function openLookupModal() {
    setOpenModal(true);
  }

  const keyPressOpenLookup = (e) => {
    if (e && e.key === "F4") {
      openLookupModal();
    }
  };

  function handleChange(args) {
    console.log(args);
    if (queryRef.current) {
      let elem = document.getElementById(ruleID).querySelector(".e-rule-value");
      queryRef.current.notifyChange(args.value, elem, "value");
    }
  }

  function handleClose() {
    setOpenModal(false);
  }

  function handlePopupApply() {
    if (queryRef.current) {
      let elem = document.getElementById(ruleID).querySelector(".e-rule-value");
      queryRef.current.notifyChange("April", elem, "value");
      handleClose();
    }
  }

  return (
    <>
      <div
        onKeyUp={keyPressOpenLookup}
        style={{ display: "flex", position: "relative" }}
      >
        <TextBoxComponent
          ref={inputRef}
          value={values ?? ""}
          change={handleChange}
          {...props}
        />
        <IconButton
          onClick={(e) => {
            e.stopPropagation();
            openLookupModal();
          }}
          style={{
            padding: "4px",
            margin: 0,
            position: "absolute",
            top: 0,
            right: 0,
          }}
        >
          <Search style={{ fontSize: "1.25rem" }} />
        </IconButton>
      </div>
      <Dialog
        open={openModal}
        onClose={handleClose}
        maxWidth="md"
        fullWidth
        scroll="paper"
      >
        <DialogTitle>Accounting Month</DialogTitle>
        <DialogContent>
          <DialogActions>
            <Button onClick={handlePopupApply} color="secondary">
              Apply
            </Button>
            <Button onClick={handleClose} color="secondary">
              Cancel
            </Button>
          </DialogActions>
        </DialogContent>
      </Dialog>
    </>
  );
}



YA YuvanShankar Arunagiri Syncfusion Team August 9, 2022 07:41 AM UTC

Hi Juliet,


We have prepared the sample based on your provided code snippet. but still, we can’t reproduce your reported query. Please refer the below sample link.


Sample link: https://stackblitz.com/edit/react-xstvmz-56utxn?file=index.js


If you still facing the issue, please share the issue reproducible sample or replicate the issue in our sample, based on that we will check and provide you a better solution quickly.


Regards,

YuvanShankar A



JK Juliet King August 9, 2022 03:51 PM UTC

It looks like part of the problem might be that I'm using material ui components along side syncfusion. I removed those, and it looks like the value part works just fine, but I do still get this error when changing operator values.

https://stackblitz.com/edit/react-xstvmz-mxzoh4?file=index.js 




JK Juliet King August 9, 2022 08:59 PM UTC

I was able to get a copy with the bug on stackBlitz, please take a look.

https://stackblitz.com/edit/react-xstvmz-mxzoh4?file=index.js,data-source.js,index.html


This contains the error with the value template change and the issue with the operator change



YA YuvanShankar Arunagiri Syncfusion Team August 11, 2022 10:22 AM UTC

Hi Juliet,


We have validated your reported query and found an issue in your provided sample code. Please ensure the below mentioned line, this is reason for script error. This line makes query builder rule empty for every change in query builder.


[index.js]:

<QueryBuilderComponent

        ref={ref}

        id={id}

        dataSource={dataSource}

        columns={columns}

        rule={!value || typeof value !== 'object' ? value : value}

        change={handleRuleChange}

        sortDirection="Ascending"

        {...props}

      ></QueryBuilderComponent>



Without the above-mentioned line, sample working fine. Please refer the below sample link.


Sample link: https://stackblitz.com/edit/react-3uugqq?file=index.js


Could you please check with above sample and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A



JK Juliet King August 11, 2022 01:11 PM UTC

Hello,

I made that change, but I'm still having the same issue. It looks like you removed template in that link, and that's the part that seems to be causing the issue. Here is an example of replacing the value and it still not working.


https://stackblitz.com/edit/react-3uugqq-5gnd4m?file=index.js,index.html



YA YuvanShankar Arunagiri Syncfusion Team August 12, 2022 05:42 AM UTC

Hi Juliet,


We have validated your reported query and please remove the below highlighted line. The rule property used for initial loading rule for query builder. But in your provided sample, change event trigger for every value change in query builder and every time setting empty rule to the query builder. It is reason for your script error. Please ensure the below code snippet.


[index.js]:

<QueryBuilderComponent

        ref={ref}

        id={id}

        dataSource={dataSource}

        columns={columns}

        rule={value}

        change={handleRuleChange}

        sortDirection="Ascending"

        {...props}

      ></QueryBuilderComponent>



Without the above-mentioned line, sample working fine. Please refer the below sample link.


Sample link: https://stackblitz.com/edit/react-3uugqq-kprjtg?file=index.js


Could you please check with above sample and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A


Loader.
Up arrow icon