Netzke demo 0.9 Bosses and Clerks

75 views
Skip to first unread message

omar

unread,
Nov 3, 2013, 2:33:26 PM11/3/13
to net...@googlegroups.com
In the Netzke demo I want to programmatically select the first boss, so the info and the clerk component are not empty when the component pop up. In other words, I want to simulate the clicking of the first boss so the info and clerks component has some content.
Please note that I am working with the last version 0.9. I tried to use listeners but without any luck. 
Any help will be much appreciated


Praveen K

unread,
Nov 6, 2013, 11:51:06 PM11/6/13
to net...@googlegroups.com
Hi Omar,

Can paste the code your working on, based on that i can tell you how to do.

omar

unread,
Nov 11, 2013, 2:05:23 PM11/11/13
to net...@googlegroups.com
***code start ****
class Bosses < Netzke::Basepack::Grid

  def configure(c)
    super
    c.model = "Boss"
  end

  
  js_configure do |c|
    
    # Overriding initComponent
    c.init_component = <<-JS
      function(){
        // calling superclass's initComponent
        this.callParent();
        // alert(this.getCount());
        // setting the viewready event
        this.on('afterrender', function() {
          console.log(this);
          alert(this.getStore().getCount());
          alert('Hit any key to continue');
          console.log(this.getStore().getAt(1));
          return true;
        }, this);
        
      }
    JS
  end
end
*** code end ******
As you can see to the above code I want to catch the afterrender event and select the first element. BUT the render has not happen yet, so I get undefined first element. How can I make this event handler to be called after the list of bosses are shown in the grid. I also tried 'show' 'beforeshow' events and  none of them worked.
Thanks a lot for your help

Praveen K

unread,
Nov 13, 2013, 12:22:30 AM11/13/13
to net...@googlegroups.com
Hi Omar,

To get the record use "this.getStore().getAt(1).data", it will contains all the information displaying in grid and primary key(id).
using id u can refresh other components.

omar

unread,
Nov 14, 2013, 4:15:52 PM11/14/13
to net...@googlegroups.com
Thanks Praveen,
It solves the problem partially. Here is the complete solution for the bosses compoent in Netzke demo. If you run this code you will see the first boss selected on every Grid page. I have to set one event listener inside other event listener. Maybe there is a better way to do that. That was the only way I could get the alert happen when the gird was displayed. Any improvements are welcome

***code start ****
class Bosses < Netzke::Basepack::Grid

  def configure(c)
    super
    c.model = "Boss"
  end

  
  js_configure do |c|
    
    # Overriding initComponent
    c.init_component = <<-JS
      function(){
           var me = this;

          // calling superclass's initComponent
          me.callParent();

         // setting the viewready event
         me.on('viewready', function(){
             me.getStore().on('load', function() {
             alert('On Load');
             record = this.getAt(0);
            me.getView().select(0);
         });
       }, me);
    JS
  end

end
*** code end ******



Reply all
Reply to author
Forward
0 new messages