drvic10k / bootstrap-sortable

adding sorting ability to bootstrap table
MIT License
513 stars 131 forks source link

Table data with rowspan (not table headers) #109

Closed marcreig closed 7 years ago

marcreig commented 7 years ago

Hi,

so if you've some normal TRs inside TBODY, and there are some TDs which have a rowspan, the sort doesn't work. It breaks all the table. Sorts OK the present column, but causes caos on all the others.

Any idea on how to solve this?

Thanks and kind regards.

drvic10k commented 7 years ago

so the desired behaviour would be to treat the rows with rowspan cells as one? how about the columns that have more cells in the rospan rows?

could you create a sample jsfiddle and describe the desired behaviour, please?

marcreig commented 7 years ago

Look, this would be the case:

https://jsfiddle.net/jz5tnq4y/12/

drvic10k commented 7 years ago

ok, this looks very broken :)

marcreig commented 7 years ago

And so?

marcreig commented 7 years ago

Hello?

drvic10k commented 7 years ago

I will have a look at it. Hopefully next week.

On Feb 3, 2017 2:04 PM, "marcreig" notifications@github.com wrote:

Hello?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drvic10k/bootstrap-sortable/issues/109#issuecomment-277242001, or mute the thread https://github.com/notifications/unsubscribe-auth/ADlKS4x3MaHhj7NJQ-Zy3vHPdcmb5usuks5rYyXMgaJpZM4LykLa .

marcreig commented 7 years ago

Excuse me,

could you take a look at it?

Thanks alot.

marcreig commented 7 years ago

News?

Thanks.

drvic10k commented 7 years ago

I found the problem, the solution might be a little more complicated

drvic10k commented 7 years ago

I am trying to figure out the desired behaviour

in the case, when you sort according to the column where the rowspan cell is, the order of the affected rows should be fixed

but what do you expect in the case, when the sorting would cause the cell to break?

then there might be a case, where the rowspan cells overlap in several columns

marcreig commented 7 years ago

Yeah, I was going to tell you that you would have to "be creative" on this... Think about it: no one has this functionality resolved. So you would probably be the first. Then your plugin go to heaven.

Take a look at this, which exemplificates what you ask for:

http://i.imgur.com/SJ18qEL.png

1) You sort first column, then rowspan is taking in account, so it sorts "normally". Drag the entire rows like they are originaly sorted.

2) Center column, normal sort. But, what happens with the previous and last column "blocks"?

3) Last column, like first one.

4) Dual cases, red cells, contained on both: first column A block, to last column Y block.

A real pain...

I guess, first step would be to normally sort single column as it is, so the ones with rowspans, sort'em like blocks. Rest of the row moves accordingly. When sorting single rows, and blocks have to be broken, do it. And on dual cases, the very same. You sort first column, last column is going to be broken.

That would be the very first move, don't you think?

drvic10k commented 7 years ago

how would you break the rowspan cell? add empty cells to fill in the gaps that are created after breaking?

the thing is, that the sorting is done by TinySort plugin, so I need to prepare the table to be sortable by it and then clean up after sorting

I was able to make it sort somehow, but the result was not perfect I will try this scenario, and I will post the observations

marcreig commented 7 years ago

No, empty cells no, just repeat the content. So in the case of first colum, the "A" block, you would write "A" to every moved row. It's like you delete the rowspan and add cells for every row with the original content on it.

Maybe that would be something like:

I would say that rowspans are only taken into account as they originally are, when you sort the column with 'em. Other times, they will brake.

marcreig commented 7 years ago

People on inet says something like:

marcreig commented 7 years ago

From another plugin:

http://stackoverflow.com/questions/16211265/sort-a-table-with-rowspan

which leads to:

https://github.com/Mottie/tablesorter/issues/806

Some other ideas there.

drvic10k commented 7 years ago

that's exactly what I did, but I didn't know what to do, if the cells couldn't be merged back, because they were separated by other rows

if it's enough to merge back what is possible, then I can do it like that

another problem that may occur is, that you can have several cells with the same content, but after sorting, it might be shuffled and not possible to be merged, although the same content will be below each other

example:

A|B
 |D
A|C

this will be adjusted before sorting to:

A|B
A|D
A|C

and then become:

A|B
A|C
A|D
drvic10k commented 7 years ago

but I understand, that almost anything is better than the current state :)

marcreig commented 7 years ago

Hey, but it's not about de content itself, it's about the rowspan! Doesn't matter if same content are on cells, but no rowspan is defined. You don't have to re-merge those cells in case you can by the sorting. That only have to be through the ones with rowspan defined on the original HTML content. On the first example you wrote:

A |
  |
A |

there is no rowspan on first column. This is just Cell, empty cell, and cell with same content like first. Isn't it?

marcreig commented 7 years ago

So, how is everything going?

marcreig commented 7 years ago

Amazing man! Did a great job. Normally works stable and I could say you got the real solution.

This case but:

https://jsfiddle.net/jz5tnq4y/13/

reacts a little strange maybe? What is it? You reattach what you can, and what you can't let it as a single cell? Sure it's the most rare and difficult case, of course (overlapped/superposed rowspans on different columns)...

drvic10k commented 7 years ago

Yes, that was a compromise. If it's possible to merge, it will be merged, if not, the cells stay split and if they get together by other sorting, they will be merged then.

drvic10k commented 7 years ago

or did you mean the 4th column?

I will investigate that issue

marcreig commented 7 years ago

Right. But maybe it needs a little cleanup. Just a bit... Look: at the example I bring on the fiddle (this last one, #13), just press any "header" when it finished loading. You will see how elements from column 4, breaks on the C4 rowspan. And a single c4 cell appear and a rowspan=2 cell too. Which makes no sense beacuse no sort has really been done already...

marcreig commented 7 years ago

Sorry, didn't seen your last answer. That's right, I precisely was meaning the 4th column. Which breaks when no reason apparently.

marcreig commented 7 years ago

Hi,

have you found anything?

Thanks!