PDA

View Full Version : grid, checkbox & odd behavior


ralph78fr
01-09-2007, 02:19 AM
Hi everyone!

I am currently fighting with grids and checkboxes. I saw several thread dealing about this, but could not find any help in the answers.

I merely want to have a grid with a checkbox to "select/unselect" rows. I already wrote some code to send the "selected" rows to the server, and this part seems to work.

On the other hand, the "normal" behavior of the checkbox and/or the grid doesn't look so normal to me.

the grid is bind to a simple dataset like
<my_ds>
<item id="1" txt="aaa" def_select="false"/>
<item id="2" txt="bbb" def_select="false"/>
<item id="3" txt="ccc" def_select="false"/>
</my_ds>

and looks like
<grid datapath="my_ds:/my_ds[1]" contentdapath="item">
<gridcolumn><checkbox datapath="@def_select"/></gridcolumn>
<gridtext datapath="@txt"/>
</grid>

the data seem to be ok (the checkboxes are checked if def_select is true, unchecked else).
but there are 2 major problems:

1) if I sort the txt column, the checkboxes looks independant. for instance, i run my app, everything is unchecked. Then i check "aaa" and sort the txt column. as a result, "ccc" will look checked, since the list will be upside down.

2) when I put more items (enough to have 2 times more items than displayed by the grid), some items will be checked as if they were paired.
(for instance, everything is unchecked, I check "aaa", scroll down and notice "kkk" has been checked as well. If i uncheck "kkk", "aaa" will be unchecked as well.
it'll be the same for "bbb" and "lll", "ccc" and ""mmm" and so on.

so if anyone experienced this before, i'll be pleased to share his knowledge.
(i really hope i did something wrong, since "sorting items" is a requisite in my project, and the 2nd problem is obviously blocking.


best regards,

Raph

pcawdron
01-09-2007, 03:19 AM
Raph,

You said... "I merely want to have a grid with a checkbox to "select/unselect" rows. I already wrote some code to send the "selected" rows to the server, and this part seems to work."

Perhaps if you drop the checkbox there is a simpler way of handling selected rows.

<canvas debug="true" >
<dataset name="test">
<this>
<that name="Me" address="123 St"/>
<that name="You" address="456 St"/>
</this>
</dataset>

<view>
<simplelayout axis="y" spacing="10" />
<grid id="myGrid" onselect="doSomething()" datapath="test:/this/" multiselect="false" width="500">
<gridtext datapath="@name">Somebody</gridtext>
<gridtext datapath="@address">Home address</gridtext>
<method name="doSomething">
Debug.write('the grid was clicked, you selected...')
var dp = myGrid.getSelection();
Debug.write(dp.xpathQuery( "@name" ));
</method>
</grid>
</view>
</canvas>

I'm new to OpenLaszlo myself, so I hope this helps. To keep things simple, I've turned off the multiselect. If you enable it you just need to realise that you'll have to test the var dp to see if it is an array or not.

Hope this helps,

Cheers,
Peter

ralph78fr
01-09-2007, 03:37 AM
well, thx, but i really need this checkbox (the idea is "which of those do you really want to include").

Anyway, the example I gave were easier than the actual application, but I discovered it was due to inheritance however I don't understand really why.

(I didn't use gridcolumn directly as in my example, but rather MyCheckColumn, which inherits from gridcolumn and encapsulate checkbox.)

thanks for helping anyway!

gplas
11-16-2007, 07:21 AM
Peter,

Thanks for me tho, I was having issues trying to select a row and this was exactly what I needed :)

Glenn