How I am using this: Whenever anything (sort, filter, page) changes I update a searchParams object in my components state and pass that searchParams off to my action to fetch results from the server. I've tried setting (and not setting) sortField and sortOrder on the actual datatable but either way I get the same results. The column field has the sortable=custom
Code: Select all
<DataTable
value={this.state.disciplines}
paginator={true}
rows={this.state.searchParams.pageSize}
totalRecords={this.state.totalCount}
first={this.state.searchParams.pageNumber}
onPageChange={this.onPageChange}
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink"
selectionMode="single"
selection={this.state.selectedRow}
onSelectionChange={this.showDrawer}
sortField={this.state.searchParams.sortBy}
sortOrder={this.state.searchParams.sortDir}
>
<Column field="name" header="Name" sortable="custom" sortFunction={this.sortItOut} filter={true} filterElement={nameFilterElement} />
<Column field="isActive" header="Active" body={this.actionTemplate} style={{ textAlign: 'center', width: '6em' }} filter={true} filterElement={activeFilter} />
Code: Select all
sortItOut = (e) => {
this.setState({ searchParams: { ...this.state.searchParams, sortBy: e.field } }, () => {
//this.search();
});
}