Search code examples
javascriptpluginschap-links-library

chap links library - network- how to get table row id


I'm using chap links library https://github.com/almende/chap-links-library/tree/master/js/src/network for drawing an area of objects.

I want to be able to use the id that I have set to an object upon click, I have this code

    function onselect() {
        var sel = network.getSelection();
        console.log("selected "+sel[0].row);
    }     

It works fine, only it retrieves the row number from the dynamically created table. I want to retrieve a value from that row (an object id that I set) but I don't know how to access it.

I have tired things like

sel[0].row.id

sel[0].row.getId()

sel[0].row[0]

But I don't know how they structure the data in their thing...

Anyonw run into this before and solved it?

This is the way I set the data

            nodesTable.addRow([45, "myObjectName", "image", "images/container_icons/icon.png"]);

Solution

  • For my app I solved it by creating a parallel array...

        //rendera objekt
        window.clickHelper = []; //keep track of container id in conjunction with hierarchy-canvas-object's id
        var i = 0; //counter for above
    

    Populating it upon every node creation...

                nodesTable.addRow([{{ c.id }}, "{{ c.name }}", "image", "{{ asset('images/container_icons/'~c.icon~'.png') }}"]);
                clickHelper[i]={{c.id}};
                i++;
    

    Then calling in data from that array on my onSelect event...

        function onselect() {
            //get selected node from network
            var sel = network.getSelection();
            sel = sel[0].row;
    
            //get path base structure
            var path = '{{ path('editGroup') }}';
    
            //fix path with the DB id of the clicked object
            path = path+clickHelper[sel];
    
            window.location.href = path;
        }
    

    The double {{ }} are TWIG templating for those unfamiliar with that. Mixed javascript and TWIG ServerSide code here, sorry.