Jump to content

DBTreeGrid doesn't display selected child record found with dataset.Locate method


Nadya

Recommended Posts

Hi!

I heed help again :unsure: Problem is in displaying the selected dbtreegrid node which was found in underlying dataset by Locate(...) method.

I have two TUniDBTreeGrid components on form. GridStructure shows structure of nodes with two levels, GridData should display info for selected node in GridStructure.

So when I use Locate to find node in manually or programmatically collapsed GridStructure, dataset position is correct and info in GridData is OK, but the selection in GridStructure displays incorrectly. I wrote "expandSelectedNode" method (as you advised me):

function beforeInit(sender, config) {
 var me = sender;
 me.expandSelectedNode = function() {
     var _selection = me.getSelectionModel().getSelection()[0];
     if (_selection) {
         _selection.cascadeBy(function(node) {
             node.expand();
         });
          sender.ensureVisible(sender.getSelectionModel().getSelection()[0]);
     }
 };
}

And after locating record I use this code:

grdStructure.JSInterface.JSCall('expandSelectedNode', []);
grdStructure.JSInterface.JSCode('Ext.defer(function(){'#1'.ensureVisible('#1'.getSelection()[0])}, 200);');

But is doesn't helph in some cases. I've made a testcase to demonstrate my problem.

TreeGridLocationTestCase

Please, do following:

1) Select node "Node1" in GridStructure, press button "Refresh info" below - Node1 is selected in GridStructure, GridData shows info for Node1 = CORRECT

2) Expand Node1, select child node "Node1_13" in GridStructure, press button "Refresh info" - Node1_13 is selected in GridStructure, GridData shows info for Node1_13 = CORRECT

3) Select Node1_13, press button "RefreshStructure" higher, press button "RefreshData" below - tree is collapsed, selection is not visible in GridStructure, GridData shows info for Node1_13 = INCORRECT

4) Expand Node1 in GridStructure, type text "Node1_14" in the edit box on the top of form,  press button "Search structure node" - node "Node1_14" is found and selected, GridData shows info for Node1_14 = CORRECT

5) Collapse tree in GridStructure, type text "Node1_15" in the edit box on the top of form,  press button "Search structure node" - tree is collapsed, selection is not visible in GridStructure, GridData shows info for Node1_15 = INCORRECT

Please, "kick me out" of this swamp, somebody!:sad:

Thank you!

Link to comment
Share on other sites

4 hours ago, Nadya said:

And I'm still here, waiting for your magic and wisdom :-)

Hello Nadya,

Magical seasonings are over :) 

But, also try this approach:

1.grdStructure

function beforeInit(sender, config) 
{
    var me = sender;
    me.expandSelectedNode = function() {
        var _selection = me.getSelectionModel().getSelection()[0];
        if (_selection) {
            _selection.cascadeBy(function(node) {
                node.expand();
            });
            sender.ensureVisible(sender.getSelectionModel().getSelection()[0]);
        }
    };

    sender._locate = function(id) {
        var node = sender.getStore().getRootNode().findChild('1', id, true);
        var pnode = node.parentNode;
        if (pnode) {
            pnode.expand();
            while (pnode.parentNode) {
                pnode = pnode.parentNode;
            }
            sender.getSelectionModel().select(node, true);
            sender.ensureVisible(sender.getSelectionModel().getSelection()[0]);
        }
    }
}

2. RefreshStructure

        ...
        if cdsStructure.Locate('ID', ID, [])
        then
        begin
            grdStructure.JSInterface.JSCallDefer('_locate', [ID], 500);
            //grdStructure.JSInterface.JSCall('expandSelectedNode', []);
            //grdStructure.JSInterface.JSCode('Ext.defer(function(){'#1'.ensureVisible('#1'.getSelection()[0])}, 200);');
        end;
        ...

 

  • Like 1
Link to comment
Share on other sites

Thank's for your help!

I've tried this - in my test project it works perfectly, but in the main project StructureGrid selects the top node after "Locate"

StructureGrid in the main project refreshing takes much more time and the tree contains much more nodes. So if I encrease the interval of JSCallDefer upto 1000 (for example) - may it help?

Link to comment
Share on other sites

17 minutes ago, Nadya said:

StructureGrid in the main project refreshing takes much more time and the tree contains much more nodes. So if I encrease the interval of JSCallDefer upto 1000 (for example) - may it help?

I've just tried to encrease even upto 4000 - doesn't help :sad:

Link to comment
Share on other sites

4 minutes ago, Sherzod said:

Sorry, the decision didn’t help you.

No, I'm really appreciate your help. As I said before - in test project it works great. But the main project is big and complicated (I'm moving it from desktop to web version) so I'm sure I do something wrong myself.

 

6 minutes ago, Sherzod said:

Maybe there is an easier way, I need to analyze more.

You're so kind! Thank you very much! I'll be waiting...

Link to comment
Share on other sites

On 7/1/2020 at 11:11 AM, Sherzod said:

2. RefreshStructure


        ...
        if cdsStructure.Locate('ID', ID, [])
        then
        begin
            grdStructure.JSInterface.JSCallDefer('_locate', [ID], 500);
            //grdStructure.JSInterface.JSCall('expandSelectedNode', []);
            //grdStructure.JSInterface.JSCode('Ext.defer(function(){'#1'.ensureVisible('#1'.getSelection()[0])}, 200);');
        end;
        ...

 

On 7/1/2020 at 2:00 PM, Nadya said:

I've just tried to encrease even upto 4000 - doesn't help :sad:

Hello Nadya, 

Can you try this approach?:

  ...
  if ID > 0
    then
    begin
        grdStructure.JSInterface.JSCall('getSelectionModel().deselectAll', []);

        if cdsStructure.Locate('ID', ID, [])
        then
        begin
            grdStructure.JSInterface.JSCode(#1'.loadlistener=()=> {'#1'._locate('+ ID.ToString +'); '#1'.store.removeListener("load", '#1'.loadlistener)};'#1'.store.addListener("load", '#1'.loadlistener);');
            //grdStructure.JSInterface.JSCallDefer('_locate', [ID], 500);
            //grdStructure.JSInterface.JSCall('expandSelectedNode', []);
            //grdStructure.JSInterface.JSCode('Ext.defer(function(){'#1'.ensureVisible('#1'.getSelection()[0])}, 200);');
        end;
    end
    else ...

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, Sherzod said:

Hello Nadya, 

Can you try this approach?: 


  ...
  if ID > 0
    then
    begin
        grdStructure.JSInterface.JSCall('getSelectionModel().deselectAll', []);

        if cdsStructure.Locate('ID', ID, [])
        then
        begin
            grdStructure.JSInterface.JSCode(#1'.loadlistener=()=> {'#1'._locate('+ ID.ToString +'); '#1'.store.removeListener("load", '#1'.loadlistener)};'#1'.store.addListener("load", '#1'.loadlistener);');
            //grdStructure.JSInterface.JSCallDefer('_locate', [ID], 500);
            //grdStructure.JSInterface.JSCall('expandSelectedNode', []);
            //grdStructure.JSInterface.JSCode('Ext.defer(function(){'#1'.ensureVisible('#1'.getSelection()[0])}, 200);');
        end;
    end
    else ...

 

Hi Sherzod!

Thank you very much, it works!!!!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...