DBTreeView duplicating elements

Hi everyone,

We’ve been struggling with various beans to display the menu options of our application… we’ve finally decided to go for DBTreeview and got it to semi-work. The problem we’re having is that it’s displaying repeated child nodes.
We have a table, named options. It contains both child and parent nodes. We have a relationship, options_to_options that contains:
idopt = idparent_opt
module = module

We expect the DBtreeview to display something like this:
Main

  • Customers
  • Deposits
  • Loans
  • Exit
    Administration
  • Roles
  • Users
  • Audit Trail

However, it’s duplicating child nodes and displaying something like this:
Main

  • Customers
  • Deposits
  • Loans
  • Exit
    Administration
  • Roles
  • Users
  • Audit Trail
    Customers
    Deposits
    Loans
    Exit
    Roles
    Users
    Audit Trail

Our code is as follows:

 /**@type {JSFoundset<db:/dbmain/options>}*/
 var _fsOpts = databaseManager.getFoundSet("dbmain","options");
 var _binding  = elements.treeview.createBinding("dbmain", "options");
 _binding.setNRelationName("options_to_options");
 _binding.setTextDataprovider("name");

if (_fsOpts.find()){
     _fsOpts.module = "FIN";   // A module is like a subsystem
     _fsOpts.skip = 0;
     _fsOpts.visible  = 1;

              if (_fsOpts.search(1,0) > 0 )  {
                     elements.treeview.addRoots(_fsMenu);
                  }
}

What could I be doing wrong?

Thank in advance,

jd

Which records are in _fsMenu you load into the treeview root ? Or did you mean to load _fsOpts, in that case what is the result of the find/search it should only contain the the top-level option records, so only ‘Main’ and ‘Administration’ in your example.

Which records are in _fsMenu you load into the treeview root ? Or did you mean to load _fsOpts

Yes, I meant to write _fsOpts.

I wasn’t loading only the lop-level records, I changed that and it worked. Thanks a lot boonstrj! :mrgreen: It made complete sense, I don’t how I didnt think of that.

OK, now I have an issue with applying filters to the relationship binded to the DBTreeview.

On options table I have the list of top level options and child options. However, the user is only allowed to view those options that he has permission to see. In order to control that, there is a permissions table that has foreign keys for options and users tables.

So, following the same example above, I have these options:

idopt     name                idparent_opt       module
1            Main                    null                  FIN
1.1         Customers                1                   FIN
1.2         Deposits                 1                   FIN
1.3         Loans                    1                   FIN
1.4         Exit                      1                   FIN
2           Administration         null                 FIN
2.1         Roles                       2                    FIN
2.2         Users                       2                 FIN
2.3         Audit Trail               2                 FIN

and the following records on permissions table:

username            idopt
test                   1
test                   1.1
test                   1.4
test                   2
test                   2.3

After logging in, the user test should only be able to see this:

Main

  • Customers
  • Exit
    Administration
  • Audit Trail

Any ideas?

Thanks,
jd

Does anyone have any suggestions to apply a filter in this scenario?