Итак, пытаясь использовать datatable в реагирующих, я хочу поставить щелчок в столбце, но получаю ошибку.
Ниже мой код:
const $ = require('jquery')
$.DataTable = require('datatables.net')
class Rmsdatatable extends Component {
constructor(props) {
super(props)
this.handletableclick = this.handletableclick.bind(this)
}
handletableclick(event) {
console.log(event)
}
componentDidUpdate() {
console.log(this.props.data)
this.$el = $(this.el)
this.$el.DataTable(
{
data: this.props.data,
scrollY: 520,
paging: false,
responsive: true,
columns: [
{
data: "vfdSno",
render: function (data, type, row) {
return '<a onClick={' + this.handletableclick.bind(this, row) + '} >' + data + '</a>'
}
},
{ data: "customerName" },
{ data: "district" },
{ data: "state" }
]
}
)
}
render() {
return (
<div style={{ 'padding': '10px' }} className="col-xs-10">
<table id="example" className="display" width="100%" ref={el => this.el = el}>
<thead>
<tr>
<th>VFD/Controller No</th>
<th>Beneficiary</th>
<th>District</th>
<th>State</th>
</tr>
</thead></table>
</div>
)
}
}
Для справки, я использую эту ссылку:
https://datatables.net/forums/discussion/38969/reload-refresh-table-after-event
Ошибка: TypeError: Cannot read property 'handletableclick' of undefined
Спасибо и ценим вашу помощь.