Loading ...
Sorry, an error occurred while loading the content.

Re: ContextMenu in DataTable Header

Expand Messages
  • Matt
    Hi Eric, In your context menu config you ve got trigger: self.dataTable.getTbodyEl() which will attach it to the body of the table. Replace with trigger:
    Message 1 of 12 , Feb 19, 2010
    • 0 Attachment
      Hi Eric,

      In your context menu config you've got
      trigger: self.dataTable.getTbodyEl()
      which will attach it to the body of the table. Replace with
      trigger: self.dataTable.getTheadEl()

      and it'll attach to the head.

      I've just done an extension to datatable to do exactly this, it's at
      http://github.com/mattparker/Yui-DataTable-extension---column-chooser

      if you want to take a look.

      Matt


      --- In ydn-javascript@yahoogroups.com, Eric Cire <codedude11@...> wrote:
      >
      > Hi Group,
      >
      > I am creating a DataTable and I need to add a ContextMenu to a header, not the body of the table. I have a table contextMenu working fine, but not sure how to link it to the header. Any ideas? The code is below.
      >
      > Using YUI 2.7.0.
      >
      > Thank you !
      >
      > Code:
      >
      > var onContextMenuClick = function( p_sType, p_aArgs ){
      > var task = p_aArgs[1];
      > if(task) {
      >
      > switch(task.index) {
      > case 0: ExportFile(); return;
      > case 1: printTable(); return;
      > case 2: alert("You clicked for a message. This is a message.");
      > }
      > }
      > }
      >
      > // Function to add Menu controls.
      > function registerMenus(){
      >
      > YAHOO.util.Event.onContentReady(self.containerDiv, function () {
      >
      > var contextMenu = new YAHOO.widget.ContextMenu("contextmenu",{trigger:self.dataTable.getTbodyEl()});
      > contextMenu.addItem("Export File");
      > contextMenu.addItem("Print Page");
      > contextMenu.addItem("Click for message!");
      > contextMenu.render(self.containerDiv);
      > contextMenu.clickEvent.subscribe(onContextMenuClick, self.dataTable);
      >
      > });
      > }
      >
    • Eric Cire
      Hi Group, Is there a way to alert the column name of a DataTable column I am in when I right click and bring up a ContextMenu? I want to have different context
      Message 2 of 12 , Feb 25, 2010
      • 0 Attachment
        Hi Group,

        Is there a way to alert the column name of a DataTable column I am in when I right click and bring up a ContextMenu? I want to have different context menus based on which column I am in, and was not able to get it working.

        I am using YUI 2.7.0 and the code I am working on is below.

        Thank you.

        Code:

            function registerBodyMenus(ColumnDefs){

                    YAHOO.util.Event.onContentReady(self.containerDiv, function () {

                        var bodyContextMenu = new YAHOO.widget.ContextMenu("bodycontextmenu", {
                            trigger: self.dataTable.getTbodyEl()
                        });

                        bodyContextMenu.addItem("Click To Get Column Name");
                        bodyContextMenu.render( self.containerDiv );
                        alert(ColumnDefs);  // Gives me array [object Object]... for each column I have
                        bodyContextMenu.clickEvent.subscribe( onBodyMenuClick, self.dataTable );

                    });
                }

                var onBodyMenuClick = function( p_sType, p_aArgs, ColumnDefs ){
                    var task = p_aArgs[1];
                    if( task ) {
                       
                        switch( task.index ) {
                            case 0:
                                alert(ColumnDefs);  // Gives me: DataTable instance yui-dt0
                                alert(ColumnDefs.getKey());  // Does not alert
                                return;
                        }
                    }
                }

      Your message has been successfully submitted and would be delivered to recipients shortly.