question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sorting is not toggled properly when used with custom 'sortType' callback function

See original GitHub issue

Using v7

Hi there! First of all thanks for all your efforts in creating such a great library.

Bug Description I did encounter a rather strange problem with the latest version (v7.0.0-rc.16): when I use a custom function for sorting, the results are sorted for one direction only. P.S: same code works fine with v7.0.0-rc.15

Additional context here is the code for the custom sorting function

const sortHelper = ({
	isAfter,
	isBefore,
	desc
}) => {
	let order

	if (isAfter) {
		order = 1
	} else if (isBefore) {
		order = -1
	} else {
		order = 0
	}

	if (desc) {
		return -order
	} else {
		return order
	}
}

const sortString = (rowA, rowB, columnId, desc) => {
	const stringA = rowA.values[columnId].trim().toLowerCase()
	const stringB = rowB.values[columnId].trim().toLowerCase()

	const isAfter = stringA > stringB
	const isBefore = stringA < stringB

	return sortHelper({
		isAfter,
		isBefore,
		desc
	})
}

here the code for the table component

const OverviewTable = (props) => {
	const columns = [
		{
			Header: <span>{translate({ text: 'FIRSTNAME' }).text}</span>,
			accessor: 'firstname',
			sortType: sortString
		},
		{
			Header: <span>{translate({ text: 'LASTNAME' }).text}</span>,
			accessor: 'lastname',
			sortType: sortString
		}
	]

	const data = props.data

	return (
		<Table columns={columns} data={data} />
	)
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gargrohcommented, Mar 3, 2020

Sort Comparator function should return -1 || 0 || 1.

Boolean will not work.

0reactions
tannerlinsleycommented, Mar 9, 2020

@mattstates, please ask your question in https://spectrum.chat/react-table 😃 Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

sorting is not toggled properly when used with custom ...
16): when I use a custom function for sorting, the results are sorted for one direction only. P.S: same code works fine with...
Read more >
jqGrid with Custom sorttype - Stack Overflow
My suggestion to use index as a function for custom sorting of local ... be called when jqGrid is initialized and not the...
Read more >
TableColumn (JavaFX 15)
Have a context menu when the user right-clicks the column header area; Have the contents of the table be sorted (using comparator ,...
Read more >
TableColumn (JavaFX 2.2) - Oracle Help Center
Have the contents of the table be sorted (using comparator , sortable and sortType ). When creating a TableColumn instance, perhaps the two...
Read more >
ParamQuery Grid Pro API Documentation for Version 8.x
Use toggle method to toggle the display state of grid dynamically. ... This is a callback function to customize sorting of pivot columns(v5.4.0)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found