Links in Listgrid

I've read many items about Listgrid and Fieldcreator but found nothing about my problem.

I want to have a button as link in a listgrid. But not a normal url, but something a c:load and the page must be loaded in a namespace (div) and must replace the listgrid.

Until now i have something like:

        <b:listGridCol dataField="Visit" label="View" width="100px" align="center">
                <b:fieldCreator type="text/javascript">
               var obutton = bb.document.createElementNS('http://www.w3.org/1999/xhtml', 'button');
               obutton.viewNode.innerHTML = 'More info';
               obutton.addEventListener('click', crLink("id=('hoofdscherm')"), false);
               controller.appendChild(obutton);
               return obutton;
 </b:fieldCreator>

In the listgrid the button with the text 'More info' is shown but the call to crlink (=function) is not executed.
Can somebody guide me to a working code.

Element creation

Hello,

When you create a button element, this as not been added to document, surely is not possible to add a listener in this moment. The easiest way to add a handler for the click event in your button is write html code and add trough innerHTML

An example:

<b:listGridCol dataField="Visit" label="View" width="100px" align="center">
  <b:fieldCreator type="text/javascript">
     var html = '<button onclick="crLink(document.getElementById(\'hoofdscherm\'))">More info</button>';
     viewNode.innerHTML = html;
   </b:fieldCreator>

fieldCreator receive the following parameters :
viewNode, controller, recordId, value

Proposed solution is not working

Huando,

I've tried your code but it is not working: The button is now shown, only the text More info is shown. The link is also not working.I am using firefox 3 as browser.

wront typing

i mean the button is not shown....

fieldCreator

Hi richardreen,

Try this code below

 <b:fieldCreator type="text/javascript">
        var oRow = controller.getProperty('localRecords')[recordId];
        var obutton = document.createElement('button');
        obutton.innerHTML = "More info";
        viewNode.appendChild(obutton);
        obutton.addEventListener('click',function(){alert('yes it is clicked')}, false);
                                    return viewNode;
 </b:fieldCreator>

Hope this helps,

Andys

Almost solved

Thanx andys, that directed me in the good direction.
Your example was working.
I changed it in the following code:

                <b:fieldCreator type="text/javascript">
                        var oRow = controller.getProperty('localRecords')[recordId];
                        var obutton = document.createElement('button');
                        obutton.innerHTML = "Details";
                        viewNode.appendChild(obutton);
                        obutton.addEventListener('click',bb.command.load('videodetail.xml',"GET",recordId, null,bb.document.getElementById('hoofdscherm')), false);
                        return viewNode;
                </b:fieldCreator>

When i load the page now it wants to load videodetail.xml for all rows in the listgrid. I only want to load after a click on the button!!

It's working

Found the solutin, just put function() and take bb.command.... as the function.

Working code is:

<b:fieldCreator type="text/javascript">
                        var oRow = controller.getProperty('localRecords')[recordId];
                        var obutton = document.createElement('button');
                        obutton.innerHTML = "Details";
                        viewNode.appendChild(obutton);
                        obutton.addEventListener('click',function(){bb.command.load('videodetail.xml',"GET",recordId, null,bb.document.getElementById('hoofdscherm'))}, false);
                        return viewNode;
                </b:fieldCreator>

Only thing left is now how to load the xml-file in the correct namespace and let it replace the listgrid.

Hi Richard, what is inside

Hi Richard,
what is inside the videodetail.xml ? Does it have html or BTL component or XEL ? An example of XML file with html and btl component inside.

<b:tabBox  xmlns="http://www.w3.org/1999/xhtml" xmlns:b="http://www.backbase.com/2006/btl">
  <b:tab>
     <button onclick="alert('hello');">say hello</button>
  </b:tab>
</b:tabBox>

~Yudi