Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to Modify Event Windows Style in event handlers?

    I am working with Calendar Widget. One of my needs is to modify an Event Window style (color, border etc) for a particular Event while I am in a OnEventClick event handler.

    This is what I tried and does NOT work.

    The purpose of the code is to change the Event style to show that a an event is selected when clicked.....

    Code:
    ...........
    @Override
        public void onEventClick(CalendarEventClick e) {
    
           CalendarEvent event = e.getEvent();
    
    //'sele' is a CalendarEvent instance variable. This holds last selected event...
    
    if (sele != null) {
    // show last event unselected
                sele.setAttribute("EventStyle", "eventWindow");
            }
    // show new event selected
            event.setAttribute("EventStyle", "selectedEvent");
    
            if (sele != event) {
                
                sele = event;
    
    //            cal.setData(cal.getData()); //fallback technique
    
    
    /* dont show Edit windows if no control pressed*/
    if (!e.isCtrlKeyDown()) {
                e.cancel();
            }
    
    }
    The above code does not work as expected. There is no effect unless user takes action equivalent to complete view refresh.

    But if user goes to other view and comes back then the changed attribute will take effect.

    An alternative is to do following in the event handler after the attribute change-

    //cal is calendar instance
    cal.setData(cal.getData()); //fallback technique

    But this is very expensive operation.

    Any suggestions how to only update style?
    Last edited by mkhadilk; 17 Dec 2009, 10:37.

    #2
    BTW, I have changed the Window style field by

    cal.setEventWindowStyleField("EventStyle");

    So that the event style is picked from attribute "EventStyle" of the CadendarEvent........

    Comment


      #3
      I need to solve this problem ASAP. Any help will be appreciated........

      Comment


        #4
        Hi mkhadilk,

        Did you ever figure this out? I swear I thought I had this working in Smartclient but can't seem to get it working in SmartGWT.

        Guy

        Comment


          #5
          Having a way to dynamically vary the rendering of events during some event handling is really needed. Did you find any way to achieve it without having to call setData()?
          See also http://forums.smartclient.com/showpo...48&postcount=8
          Last edited by d.cavestro; 17 Jun 2014, 04:06.

          Comment


            #6
            We can't really help without at least knowing your exact SmartGWT version.

            What is the purpose of this style change? Is it purely to show an event as selected?

            Comment


              #7
              I'm using SmartGWT LGP 4.1p (20140408 nightly build) SmartClient Version: v9.1p_2014-04-08/LGPL Development Only (built 2014-04-08)
              I need to highlight one or more events when either:
              * the user click on a calendar event (hence resembling a single event selection)
              * the user selects some rows from a listGrid whose records are linked by a foreign key on the calendar event record.

              I've seen that simply invoking CalendarEvent.setEventWindowStyle() is not enough.
              If I call Calendar.setData () passing actual calendar data then the refresh is triggered and the new style becomes visible.
              Please also note that even Calendar.redraw() is not enough.
              Originally posted by Isomorphic View Post
              We can't really help without at least knowing your exact SmartGWT version.

              What is the purpose of this style change? Is it purely to show an event as selected?

              Comment


                #8
                We've added a couple of new Calendar APIs, refreshEvent(event) and setEventStyle(event, styleName).

                Please retest with a build dated June 18 or later.

                Comment


                  #9
                  Amazing! I'm going to test your new api as soon as it's available.
                  Many thanks for the quick feedback.

                  BTW I leave here an additional workaround for guys using a databound calendar but - for whatever reason - cannot easily use the new API.
                  Calling DataSource.updateCaches() is better than calling Calendar.setData(), as using the latter workaround imply loosing changes notifications from the datasource.

                  Code:
                          ...
                          calEvent.setEventWindowStyle ('hilitedEventWindow');//set hilite custom style on the event
                          updateEventsCache (calEvent);
                      }
                      ...
                      protected void updateEventsCache(CalendarEvent... events) {
                          DataSource dataSource = getDataSource();
                          DSResponse dsResponse = new DSResponse(dataSource.getID(), DSOperationType.UPDATE, events);
                          dataSource.updateCaches(dsResponse);
                      }
                  Originally posted by Isomorphic View Post
                  We've added a couple of new Calendar APIs, refreshEvent(event) and setEventStyle(event, styleName).

                  Please retest with a build dated June 18 or later.

                  Comment


                    #10
                    Now it works like a charm

                    I confirm it works like a charm. Many thanks.
                    Originally posted by Isomorphic View Post
                    We've added a couple of new Calendar APIs, refreshEvent(event) and setEventStyle(event, styleName).

                    Please retest with a build dated June 18 or later.

                    Comment


                      #11
                      Calling refreshEvent() fails for the month view

                      Calling refreshEvent() on the day and week views works fine, but calling it with the month view activated produces an error.
                      That's because in Calendar.js the refreshEvent function calls getCurrentEventCanvas(), which is not available on the month view.
                      Code:
                      refreshEvent : function (event) {
                          var view = this.getSelectedView();
                          var win = view.getCurrentEventCanvas(event);//fails here complaining "TypeError: undefined is not a function"
                          if (win) {
                              win.setEvent(event)
                          }
                      },
                      PS: I've notices that through the entire source file several calls to getCurrentEventCanvas() are commented out.

                      Comment


                        #12
                        I've seen later you have fixed the issue implementing a no-op getCurrentEventCanvas() for the month view and modified the relevant documentation to reflect the fact that calling refreshEvent or setEventStyle has no effect in the month view.
                        Now it works fine. Many thanks!

                        Comment

                        Working...
                        X