triggers the toggle button from the cell props grid and removes spaces in the column table

1 Answer 59 Views
Grid
Noor
Top achievements
Rank 1
Iron
Noor asked on 29 Jan 2022, 02:39 AM

I created an open/close toggle button on the grid using a custom cell props that triggers a new detail row on the row detail props in the Grid component, how do I use it? and parse setState from component detail row to component button?

and why if the toogle condition is in a false column in the table it always leaves a space? here's an example


1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 31 Jan 2022, 06:18 AM

Hello,

I made an example using a custom cell and it is working as expected on my end:

https://stackblitz.com/edit/react-abh1id-x1uzs8?file=app/main.jsx

If the issue still occurs, please share an example and I will be happy to take a look at it.

Regards,
Stefan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Noor
Top achievements
Rank 1
Iron
commented on 03 Feb 2022, 08:08 AM

Hi Stefan thanks for your answer, but what if I want to render a different API inside a GridDetailRow ?

can you give me an example

Stefan
Telerik team
commented on 03 Feb 2022, 08:39 AM

Hello,

The detail row is a fully custom component. The developer has full control of what to render inside of it:

class DetailComponent extends GridDetailRow {
  render() {
    const dataItem = this.props.dataItem;
    return (
      <section>
        <p>
          <strong>In Stock:</strong> {dataItem.UnitsInStock} units
        </p>
        <p>
          <strong>On Order:</strong> {dataItem.UnitsOnOrder} units
        </p>
        <p>
          <strong>Reorder Level:</strong> {dataItem.ReorderLevel} units
        </p>
        <p>
          <strong>Discontinued:</strong> {dataItem.Discontinued}
        </p>
        <p>
          <strong>Category:</strong> {dataItem.Category.CategoryName} -{' '}
          {dataItem.Category.Description}
        </p>
      </section>
    );
  }
}


If there is a specific issue, please let me know.
Noor
Top achievements
Rank 1
Iron
commented on 04 Feb 2022, 11:26 AM

I have a problem when the toggle is opened it should call the GET Details API with the key salesplanID, but why is the expanded property having problems?


here is my code snippet: 


const getDataRemark = (props) => {
    setPageError(false);
    setDataLoading(true);
    
    const salesplanKeyId = props.dataItem;
    const withQuery = require('with-query').default;
    const url = `${API_URL}/api/BankLeasing/Remarks/remarks`;
    const query = withQuery(url, {
      salesplanKeyId
    });
    try {
      requestHandler(query).then((dataRemark) => {
        setDataRemark(dataRemark);
        setDataLoading(false);
      })
    } catch (err) {
      console.log(err.message);
      setDataLoading(false);
    }
  }

  const myCell = (props) => {
    let dataItem = props.dataItem['salesplanID'];
    return (
      <td className="k-hierarchy-cell">
        <Button onClick={() => expandChange(dataItem)} tabIndex="-1">
          Detail
        </Button>
      </td>
    );
  }

  const expandChange = (event) => {
    getDataRemark(event);
    event.expanded = !event.value
    setExpanded((prevExpanded) => !prevExpanded);
  }

Stefan
Telerik team
commented on 04 Feb 2022, 11:38 AM

Hello,

Thank you for the code. 

That occurs because we are passing the dataItem to the expandChange method, not an actual event. The dataItem is the row data. Please double check the provided example again for the correct structure.

<Button onClick={() => expandChange(dataItem)} tabIndex="-1"

Noor
Top achievements
Rank 1
Iron
commented on 09 Feb 2022, 09:14 AM

Hi Stefan, 

i have a case of get data Remark in component Page1 by initializing state [dataRemark, setDataRemark], how to parse dataRemark to component class GridDetailRow

here is my code snippet:


class DetailComponent extends GridDetailRow {
  render() {
    const dataItem = this.props.dataItem
    return (
    	<div>{dataItem.remarks}</div>
      	<div>{dataItem.createdBy}</div>
      	<div>{dataItem.lastUpdateat}</div>
    )
  }
}

const Page1 = (props) => {
  const [dataRemark, setDataRemark] = useState()
  
  const getDataRemark = (props) => {
    setPageError(false);
    setDataLoading(true);

    const SalesplanKeyId = props.salesplanID;
    const withQuery = require('with-query').default;
    const url = `${API_URL}/api/Remarks/remarks`;
    const query = withQuery(url, {
      SalesplanKeyId,
    });
    try {
      requestHandler(query).then((dataRemark) => {
        setDataRemark(dataRemark);
        console.log(dataRemark, 'INI DATA REMARKS')
        setDataLoading(false);
      });
    } catch (err) {
      console.log(err.message);
      setDataLoading(false);
    }
  };
}

Stefan
Telerik team
commented on 09 Feb 2022, 10:39 AM

Hello,

React has a functionally called React.Context that is made for these cases. The idea is to pass information between components:

https://reactjs.org/docs/context.html

This is an example of how React.Context can be used with the DetailRow:

https://stackblitz.com/edit/react-6ipwp1-2ainkm?file=app/main.jsx

Tags
Grid
Asked by
Noor
Top achievements
Rank 1
Iron
Answers by
Stefan
Telerik team
Share this question
or