Skip to content

sortFunc does not work if using multiple times the same dataField #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jfremy opened this issue Apr 27, 2016 · 5 comments
Open

sortFunc does not work if using multiple times the same dataField #425

jfremy opened this issue Apr 27, 2016 · 5 comments

Comments

@jfremy
Copy link
Contributor

jfremy commented Apr 27, 2016

Hi,
I'm creating an issue first before working on some code to fix this to get your opinion.
The issue is the following:
I use the same dataField in multiple columns (I do so because the property targeted by dataField is an object and I display one part or another of the object depending on the column).
I also want to be able to sort those columns based on the displayed information.
So that requires to use a custom sortFunc.
However, since TableDataStore keys the colInfos structure based on the dataField value, in the end, there is only one set of sorting options available.
I cannot use the sortFuncExtraData object to workaround this since it's subject to the same issue.

The only option I see to fix this is keep the array structure provided in the input to Bootstrap table and update the sort / filter part of the code to use the index of the column rather than the dataField + update calls to this code.

What do you think?
Is that an approach you would accept in a pull request?

@AllenFang
Copy link
Owner

@jfremy, I seems to know your problem, but I want to be certainly to get this problem, so any examples to reproduce it?

The only option I see to fix this is keep the array structure provided in the input to Bootstrap table and update the sort / filter part of the code to use the index of the column rather than the dataField + update calls to this code.

If it's the only one solution, I think it's ok, but we need do it carefully and testing more.

Anyway, you can open a PR, but I just want a example for me to check this :)

Thanks you contribution. You did a great job!

@AllenFang
Copy link
Owner

BTW, if react-bootstrap-table support the nest data, maybe there's no problem for you. Anyway I just guess... Because #418 try to solve the nest data problem, but I need more testing and this PR loss some important thing.

@jfremy
Copy link
Contributor Author

jfremy commented Apr 28, 2016

Hi,
I had a quick look at #418 and I think this would let me work around the bug.
I would just give a distinct dataField value for each column and provide the correct dataAccess method for each. Then TableDataStore would not be confused anymore by multiple identical dataField values.

The bug itself would still be present though.

@AllenFang
Copy link
Owner

@jfremy, I thinks so too, but this PR need some improvements so that this issues may not be fixed quickly.

@jfremy
Copy link
Contributor Author

jfremy commented May 1, 2016

Here's a simple example that triggers the issue

Let's assume your data is:
[ {id:1, obj: {k1: "a", k2: "1"}}, {id:2, obj: {k1: "b", k2: "2"}}, {id:3, obj: {k1: "c", k2: "3"}}, ]

and the columns properties are:
[ {dataField: "id", isKey: true}, {dataField: "obj", dataFormat: (cell) => cell.k1, dataSort: true, filter: {type: "TextFilter"}, filterFormatted: true, sortFunc: (a,b,order,sortField) => a[sortField].localeCompare(b[sortField]) * (order === "desc" ? -1 : 1)}, {dataField: "obj", dataFormat: (cell) => cell.k2} ]

Then sortFunc will never be called because the last column (order matters) will essentially "overwrite" the settings that were defined for the second column.
Same problem for filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants