我有以下带有数据表的组件:
import React, { Component } from 'react'
import { Link } from 'react-router'
import { PanelContainer, Panel, PanelBody, Grid, Row, Col } from '@sketchpixy/rubix'
import $ from 'jquery'
import DataTable from 'datatables.net'
$.DataTable = DataTable
const columns = [{
title: '<input type="checkbox" />',
data: 'check',
}, {
title: 'Foto',
data: 'avatar',
}, {
title: 'Nombre',
data: 'name',
}, {
title: 'Dirección',
data: 'address',
}, {
title: 'Clasificación',
data: 'clasification',
}, {
title: 'Editar',
data: 'editLink',
render: x => `<a href="${x}"><i class="icon-fontello-edit"></i></a>`, // <-- this line i'm interested!
}]
class Table extends Component {
transform(content) {
return content.map(x => ({
...x,
check: '<input type="checkbox" />',
avatar: '<img src="/public/imgs/app/nico.jpg" width="40" height="40" style="border-radius: 100%;">',
clasification: `<i class="${x.clasification.icon}"></i> ${x.clasification.name}`,
}))
}
componentDidMount(nextProps, nextState) {
this.table = $(this.refs.main).DataTable({
dom: '<"data-table-wrapper"tip>',
data: [],
columns,
language: {
info: 'Mostrando _START_-_END_ de _TOTAL_ puntos',
infoEmpty: 'No hay puntos',
paginate: {
next: 'Siguiente',
previous: 'Anterior',
},
},
})
}
componentWillUpdate() {
this.table.clear()
this.table.rows.add(this.transform(this.props.data))
this.table.draw()
}
componentWillUnmount() {
$('.data-table-wrapper')
.find('table')
.DataTable()
.destroy(true)
}
render() {
return (
<table
className="table table-striped hover"
cellSpacing="0"
width="100%"
ref="main"
/>
)
}
}
export default p =>
<PanelContainer>
<Panel>
<PanelBody>
<Grid>
<Row>
<Col xs={12}>
<Table data={p.data} />
</Col>
</Row>
</Grid>
</PanelBody>
</Panel>
</PanelContainer>
问题是,对于数据表,我需要使用react-router呈现链接,使用锚链接()不是解决方案,因为它会重新呈现整个页面。所以我需要在具有指定链接的列中呈现一个自定义组件。链接是用 ID 构建的。