【问题标题】:How to use cellRenderer to navigate to some route?如何使用 cellRenderer 导航到某条路线?
【发布时间】:2023-01-10 00:15:37
【问题描述】:

我正在使用 AgGrid 并希望有一个带有链接的单元格,我想在单击链接时导航到某个 React 路由。

cellRenderer: 'linkColRenderer'

出于某种原因,以下 linkColRenderer 代码不起作用

import React from 'react';

export default (props) => {

    var link = document.createElement('a');
    link.href = '#';
    link.innerText = props.value;
      link.addEventListener('click', (e) => {
        e.preventDefault();
        console.log(props.data.id);
    });
    return (
        <>
            <span>{link}</span>
        </>
    );

    const goToDetails = (params) => {
        //Go to some route...via props.history.push 
    }
  
    //return <a href="javascript:;" style={{color: '#000000'}}>{props.value}</a>
};

【问题讨论】:

    标签: reactjs react-hooks ag-grid custom-renderer


    【解决方案1】:
    In this example, the goToDetails function is called when the link is clicked, and it uses the history.push method to navigate to the /details/:id route, where :id is the id field of the clicked cell's data.
    

    然后,您可以在 AgGrid 中使用此单元格渲染器,如下所示:

    import React from 'react';
    

    导出默认值(道具)=> {

    var link = document.createElement('a');
    link.href = '#';
    link.innerText = props.value;
      link.addEventListener('click', (e) => {
        e.preventDefault();
        console.log(props.data.id);
    });
    return (
        <>
            <span>{link}</span>
        </>
    );
    
    const goToDetails = (params) => {
        //Go to some route...via props.history.push 
    }
    
    //return <a href="javascript:;" style={{color: '#000000'}}>{props.value}</a>
    

    };

    In this example, the goToDetails function is called when the link is clicked, and it uses the history.push method to navigate to the /details/:id route, where :id is the id field of the clicked cell's data.
    

    然后,您可以在 AgGrid 中使用此单元格渲染器,如下所示:

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 2016-12-02
      • 2017-02-26
      • 2016-03-18
      相关资源
      最近更新 更多