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>
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>