0

Context menu problem in php table

Hello,

I have a problem with YUI context menu. I want the menu to show different links (with product_id) in every row. I have been struggling with this for days no without result.

My code is as follow:
Code:

$result = dbquery("SELECT ..........

echo "<table id='dataset' style='vertical- align: bottom' cellpadding= '0' cellspacing= '0' width='".$laius. "' class='table11' >";
echo "<tr><td >TABLE HEADER</td>< /tr>";

while ($data = dbarray($result) )
{
//THIS IS THE VARABLE I NEED TO ADD TO EVERY ROWS CONTEXT MENU LINK
$product_id= $data['data_ product_id' ];

?>
<script type="text/javascri pt">

YAHOO.util.Event. onContentReady( "dataset" , function () {
var Dom = YAHOO.util.Dom;

var row = this.contextEventTa rget;

var oContextMenuItems = {

"type1": [
{ text: "First link description" , url: "../products. php?action= edit&data_ product_id= <?print($ product_id) ; ?>" },
{ text: "Second link description" , url: "http://www.google. com" }
],


"type2": [
{ text: "First link description" , url: "../products. php?action= edit&data_ product_id= <?print($ product_id) ; ?>" },
{ text: "Second link description" , url: "http://www.neti. ee" }
]
};

var oSelectedTR;

function onContextMenuBefore Show(p_sType, p_aArgs) {
var oTarget = this.contextEventTa rget,
aMenuItems,
aClasses;

if (this.getRoot( ) == this) {

oSelectedTR = oTarget.nodeName. toUpperCase( ) == "TR" ?
oTarget : Dom.getAncestorByTa gName(oTarget, "TR");

if (Dom.hasClass( oSelectedTR, "odd")) {
aClasses = oSelectedTR. className. split(" ");
aMenuItems = oContextMenuItems[ aClasses[ 0]];
}
else {

aMenuItems = oContextMenuItems[ YAHOO.lang. trim(oSelectedTR .className) ];
}

this.clearContent( );
this.addItems( aMenuItems) ;
this.render( );

Dom.addClass( oSelectedTR, "selected");
}
}

function onContextMenuHide( p_sType, p_aArgs) {
if (this.getRoot( ) == this && oSelectedTR) {
Dom.removeClass( oSelectedTR, "selected");
}
}

var oContextMenu = new YAHOO.widget. ContextMenu( "contextmenu" , {
trigger: "dataset",
lazyload: true
});

oContextMenu. subscribe( "beforeShow" , onContextMenuBefore Show);
oContextMenu. subscribe( "hide", onContextMenuHide) ;

});
</script>
<?php


echo "
<tr class='type1' ><td>FIRST ROW</td></tr>
<tr class='type2' ><td>SECOND ROW</td></tr>
.......
Table row takes menu items according to id (type1, type2 etc). But as my table is created from mysql database dynamically, it does'n work like that.

Is there any solution for that?

Thank you in advance!

by
1 Reply
  • Here's where the YUI Community hangs out. I'm sure they can help :)Community Manager, YDN
    0

Recent Posts

in General Discussion at YDN