Tree selectItem doesn't work

I have a working tree using smart rendering. There is a modal window in my app that creates a new entry in the database that I’d like the tree to display after insertion. Here is what works and what doesn’t:

tree.openItemsDynamic( resobj.matches, true ); <--- WORKS tree.selectItem( resobj.last ); <--- WORKS tree.focusItem( resobj.last ); <--- DOES NOT SCROLL TO FOCUSED ITEM

Here’s the tree definition:

[code]tree = new dhtmlXTreeObject( ‘tree_div’, ‘100%’, ‘100’, 0 );
tree.setImagePath(“/api/dhtmlx/dhtmlxTree/codebase/imgs/csh_winstyle/”);
tree.setSkin(‘dhx_skyblue’);
tree.enableSmartRendering(true);
tree.attachEvent( “onSelect”, function(id,ind){ cpe_detail(id); });
tree.setXMLAutoLoading(“status_connector.php”);
tree.loadXML(“status_connector.php”);

#tree_div {
border: 1px solid #FFFFFF;
height: 100%;
width: 450px;
overflow-y: auto;
overflow-x: hidden;
}

#info {
width: 450px;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
}[/code]

Is there something I’m doing wrong that you can see?

Thank you,
John

There is not enough of data.
Could you provide us your tree structure (“status_connector.php”)?

Here’s status_connector.php:

[code]<?php

This code is what the GUI uses to grab data from MySQL in XML format

function leaf_objects($row)
{
$request_num = $row->get_value(‘request_num’);

$msnum = $row->get_value('msnum');

if ( $request_num < 0 )
{
	$ts = $row->get_value('ticket_status');

	switch ($ts)
	{
		case 12:
			$clr = 'red';
			break;
		case '':
			$clr = 'green';
			$stat = 'Submitted';
			break;

		default:
			$clr = 'green';
	}

	$row->set_value( 'leaf',  $row->get_value('item') . " - <b><font color='$clr'>$stat" );
}
elseif ( $request_num == 0 )
{
	$row->set_value( 'leaf',  "$msnum - " . $row->get_value('coname') );
	$row->set_userdata( 'acct', $row->get_value('acctnum') );
}
else
{
	$dt = str_replace( '/', '-', $row->get_value('datetime_s') );
	$s = explode( ' ', $dt );
	$t = explode( ':', $s[1] );

	$vendor = $row->get_value('vendor');

	$row->set_value( 'leaf', "Req $request_num: $vendor: " . $s[0] . ' @ ' . $t[0] . ':' . $t[1] . ' ' . $s[2] );

	$row->set_userdata( 'acct', $row->get_value('acctnum') ); # set attribute in leaf object
}

$row->set_userdata( 'req', $request_num ); # set attribute in leaf object
$row->set_userdata( 'psr', $msnum ); # set attribute in leaf object

}

@session_start();

require(‘config_settings.php’);

$res = mysql_connect( $MYSQL_HOST, $MYSQL_ID, $MYSQL_PW );

mysql_select_db(‘test’);

require("…/api/dhtmlx/dhtmlxConnector/codebase/tree_connector.php");

$tree = new TreeConnector($res);

$tree->event->attach( “beforeRender”, “leaf_objects” );

$tree->dynamic_loading(true);

$sql = “SELECT t.msnum, t.request_num, t.mainId, t.parentId, adr.coname, adr.acctnum, t.datetime,
t.datetime_s, op.partnum, p.item, t.vendor, op.ticket_status, 0 AS leaf
FROM tree t
LEFT JOIN cust_address adr ON t.address_idx = adr.idx
LEFT JOIN order_parts op ON t.msnum = op.msnum AND t.mainId = op.mainId
LEFT JOIN parts p ON op.partnum = p.partnum
WHERE t.status = ‘O’
ORDER BY t.msnum ASC, t.request_num ASC”;

$tree->render_sql( $sql, “mainId”, “leaf, datetime, datetime_s”, ‘’, ‘t.parentId’ );
?>
[/code]

Oh, sorry…
tree.enableSmartRendering(true);
and
tree.setXMLAutoLoading(“status_connector.php”);
will not work togeter: these 2 methods are incompatible

Oh - I missed that. Thanks for pointing it out. Which is best to use? I’ve got a small tree now but it’s going to grow rather large.

Thanks,
John

I commented out the following:

//tree.enableSmartRendering(true);

I then cleared my browser cache and tried again. The same problem persists where the focusItem won’t scroll the selected item into view.

Thank you,
john

You need to be sure that you want to select and focus the item, which is alreday loaded.

I know what I need to load and issue this:

tree.openItemsDynamic( resobj.matches, true ); 

But is there a callback that I can use that ensures that the data is loaded before I do the selectItem and focusItem? I think you’re correct about the data not being loaded because if I try a 2nd time the focusItem works as intended.

Thank you,
John

Please, find the logic of the sample
dhtmlx.com/docs/products/dht … tions.html
in “Open item 2-3-1” case - it must be the same as yours.

Thank you.

You are welcome!