PDA

View Full Version : Search a grid


tglines
04-08-2009, 10:51 AM
I have the following code. It displays a grid of all the crons running on a series of machines all on the same network. The display part works quite well.
My question is this:
I would like to be able to seach the grid for a given string (onclick handler for the button). This works to a point, it will only select the row if it is visible. How can I make it search the whole grid and set the scroll so the selected row is in the visible view.

I'm running OL 4.3.0


<canvas>

<dataset name="crontab" type="http"
src="http://xxxxxxxxxxxxxxxxxxxxx/cgi-bin/CronGui.cgi"
request="true" timeout="600000" />

<simplelayout axis="y" spacing="5" />

<statictext text="Current Crons on the Network" fontsize="24" fontstyle="bold"
align="center" fgcolor="0xFF0000" />

<view align="center">
<simplelayout axis="x" spacing="5" />
<edittext name="searchtext" />
<button name="search" text="Search">
<handler name="onclick">
<![CDATA[
var obj = main.details.content.rowparent.searchSubviews( 'text', parent.searchtext['text'] );
Debug.write( obj['immediateparent'] );
obj['immediateparent'].select();
]]>
</handler>
</button>
</view>

<view name="main" align="center" clip="true">
<grid name="details" height="700" datapath="crontab:/Crontab/"
contentdatapath="user/host/cron" multiselect="false" rowheight="50" bgcolor="0xEEEEEE"
bgcolor0="0xDFDFDF" bgcolor1="0xEFEFEF">
<gridcolumn text="User" width="75">
<text datapath="../../@login" />
</gridcolumn>
<gridcolumn text="Host" width="75">
<text datapath="../@hostname" />
</gridcolumn>
<gridcolumn text="Status" width="75">
<checkbox value="$path{'@status'}" xoffset="${10 - parent['width'] / 2}"
yoffset="-5" enabled="false" />
</gridcolumn>
<gridcolumn text="Min" width="75">
<edittext datapath="@min" clickable="false" />
</gridcolumn>
<gridcolumn text="Hour" width="75">
<edittext datapath="@hr" />
</gridcolumn>
<gridcolumn text="Day" width="75">
<edittext datapath="@day" />
</gridcolumn>
<gridcolumn text="Month" width="75">
<edittext datapath="@mon" />
</gridcolumn>
<gridcolumn text="WeekDay" width="75">
<edittext datapath="@dow" />
</gridcolumn>
<gridcolumn text="Cmd" width="500">
<edittext name="a" multiline="true" width="100%" height="50" datapath="@cmd">
<handler name="oninit">
<![CDATA[
this.field[ 'fakeScroll' ] = this.field[ 'scroll' ];
var del = new LzDelegate( this, "doScroll" );
del.register( this.field, "onfakeScroll" );
]]>
</handler>
<handler name="onscroll" reference="field">
<![CDATA[
if( field.scroll != field.fakeScroll ){
field.setAttribute( 'fakeScroll', ( field.scroll -1 ) * -1 );
}
]]>
</handler>
<method name="doScroll" args="arg">
<![CDATA[
field.setScroll( ( -1 * field.fakeScroll ) + 1 );
]]>
</method>
</edittext>
<scrollbar scrolltarget="parent.a.field" scrollattr="fakeScroll"
scrollmax="${parent.a.field.maxscroll + parent.a.height - 1}" stepsize="1"
visible="${scrollable}" align="right" />
<text datapath="@msg" />
</gridcolumn>
<gridcolumn width="20" />
</grid>
</view>


</canvas>

pugmaster
04-08-2009, 11:55 AM
You need to use an XPath expression to search the dataset. Laszlo only supports a subset of XPath, but it contains enough functionality to satisfy your needs. Then you'll need to determine the offset of the selected data node within the dataset and use that offset within the grid to highlight the displayed row.

- Norman Klein
Author: Laszlo in Action

tglines
04-08-2009, 12:25 PM
I think I understand the searching part. I assume the position() method will give me the position in the dataset, do I then use something like selectItemAt() method to select the grid row and will that bring the row into the visible portion of the grid?

kmeixner
09-08-2010, 09:38 AM
Note: See my last post at http://forum.openlaszlo.org/showthread.php?p=46756#post46756 (http://forum.openlaszlo.org/showthread.php?p=46756#post46756) for an example of how I figured out how to do this. It might not be the best way but it works.