View Issue Details

IDProjectCategoryView StatusLast Update
0009007Multi Theft Auto : San AndreasGUIpublic2018-02-20 23:58
Reporterjoaosilva099Assigned ToTalidan 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version1.5.2 
Summary0009007: Formatting bug when adding rows to a sorted gridlist
Description

I can't explain it by words, I will tell an example:
You have a gridlist with this format:
1 2 3

A S D
B N M
C V B
And you sort it on column 1 descending, it will become like this:
1 2 3

C V B
B N M
A S D
Now you use guiGridListClear and it becomes like this:
1^ 2 3

Now use this code:
for k=1, 3 do
if k == 1 then
local r = guiGridListAddRow(grid)
guiGridListSetItemText(grid, r, 1, "A")
guiGridListSetItemText(grid, r, 2, "S")
guiGridListSetItemText(grid, r, 3, "D")
elseif k == 2 then
local r = guiGridListAddRow(grid)
guiGridListSetItemText(grid, r, 1, "B")
guiGridListSetItemText(grid, r, 2, "N")
guiGridListSetItemText(grid, r, 3, "M")
else
local r = guiGridListAddRow(grid)
guiGridListSetItemText(grid, r, 1, "C")
guiGridListSetItemText(grid, r, 2, "V")
guiGridListSetItemText(grid, r, 3, "B")
end
end

The grid list will become like this:
1^ 2 3

C
B
A V B

This is because when you add the second row, first column "B" it will send that row to the top and consequently the 2nd and 3rd columns will be editted on the row that's at the bottom which is actually the wrong row. At the end you will have the gridlist like above with first and second rows with the second and third collumn values bugged and the last row will have the first column right and the second and third columns wrong.

Steps To Reproduce

I think you understood above. I will leave a script as attachment you can check it to try to understand better because I think I didn't explain it good.

Additional Information

I hope this gets fixed

TagsNo tags attached.

Relationships

related to 0009793 new New issues Gridlist sorting causes bugs 

Activities

joaosilva099

2015-08-21 01:30

viewer   ~~0023985

I am working around with this disabling sorting of the gridlist which I need to clear and update later.

sbx320

2015-08-21 02:06

administrator   ~~0023987

In the source code we can find (CGUIGridList_Impl.cpp)
// If the list is sorted and we just changed an item in the sorting column,
// re-sort the list.
if ( win->getSortDirection () != SortDirections::None &&
win->getSortColumn () == GetColumnIndex ( hColumn ) )
{
win->setSortColumn ( win->getSortColumn () );
return GetItemRowIndex ( pItem );
}

The returned new row is not exposed to Lua. A solution for this would be to delay the sorting until the gridlist is rendered again. Alternatively we could return the new row from guiGridListSetItemText instead of true.

joaosilva099

2015-08-21 03:21

viewer   ~~0023990

"Alternatively we could return the new row from guiGridListSetItemText instead of true."

But what about if we don't know which column is being used to sort? I think sort reseting when clearing a gridlist would be great.

sbx320

2015-08-21 03:25

administrator   ~~0023991

You wouldn't need to worry about that:

Your above code would be rewritten to:

local r = guiGridListAddRow(grid)
r = guiGridListSetItemText(grid, r, 1, "B")
r = guiGridListSetItemText(grid, r, 2, "N")
r = guiGridListSetItemText(grid, r, 3, "M")

r would always reflect row the item is in.

arranTuna

2015-08-21 11:56

manager   ~~0023993

guiGridListClear has had this bug for as long as I can remember, I've always just had to destroy the GUI and make another instead.

joaosilva099

2015-08-21 15:11

viewer   ~~0023996

Not a functional way arranTuna, in my opinion. And it's not about guiGridListClear. If you keep adding rows after sorting the gridlist (without clearing it) it will still bug this way.

joaosilva099

2015-09-11 18:41

viewer   ~~0024069

So?

Talidan

2016-07-03 13:43

administrator   ~~0024888

https://github.com/multitheftauto/mtasa-blue/commit/36aa067c03ba37e1ad1c40c4766abb552d103bcc

qaisjp

2016-07-03 17:25

administrator   ~~0024892

Added in revision https://buildinfo.mtasa.com/?SHA=36aa067c03ba37e1ad1c40c4766abb552d103bcc

arranTuna

2018-02-20 23:58

manager   ~~0026441

This was added in 1.5.2

Issue History

Date Modified Username Field Change