Announcement

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

    Calendar with Google Gears backend and pagination

    Hello,

    In my application I need to use Calendar from SmartGWT library, but with Google Gears backend. I've read these threads:

    http://forums.smartclient.com/showthread.php?t=7136&highlight=Calendar
    http://forums.smartclient.com/showthread.php?t=1192
    http://forums.smartclient.com/showthread.php?t=4814&page=2

    and they were very helpful. I have almost finished my work.

    But I have big problem regarding the use of my application in real environments - I cannot get an idea of how to do paging in Calendar. It was fairly easy with grid and everything worked fine (startRow,endRow,totalRows). But for calendar whey I try to use (startRow,endRow,totalRows) I get the following results:
    - If I set totalRows to what I'm just returning - the calendar will never ask me for more events and nothing except for the current view will be available in the GUI
    - If I set total rows to some big value, then the framework keeps calling my backend (actually DataSource.getClientOnlyResponse()) for more rows infinitely.

    - Is there anyone who can explain me how does this caching mechanism work so that I could implement my DataSource for calendar with paging?
    - What can I do to make the framework trigger one backend query per calendar view?
    - Will it still work when the user navigates over the calendar?

    #2
    The Calendar does not do startRow/endRow paging. If you want to implement it yourself, use the DateChanged() event to find out when the visible date range has been changed, and use getChosenDate() to find out the current chosen date. We recommend paging at the granularity of the biggest view that you are using (eg if using month view, page by month).

    Comment


      #3
      The selection works fine for me. Now I seem to have a problem with adding/removing/updating events in the calendar. I have coded my custom (I mean really custom) window for event details. I don't know what API to call when I want to say the Calendar widget that it needs to add an event on the GUI.

      My flow is the following:
      - I intercept calendar click and make the standard event editing window not appear
      - I display my own editing window
      - after the user clicks OK I save my data to the DB
      - I want to say 'add event' just to the widget, but it seems to be a problem.

      I tried to call Calendar.addEvent() to do that. I got to the point where in my data source in method setClientOnlyResponse I should do something after receiving DSOperationType.ADD, but actually I don't know what code to put there.

      Comment


        #4
        SmartClient Version: v8.2p_2012-04-07 (smartgwtee-3.0p)

        I have been trying to page on calendar to no avail.

        I tried to override the onDateChage as below:
        @Override
        public void onDateChanged(DateChangedEvent event) {
        setInitialCriteria(getFetchCriteria());
        }

        Where I would set a parameter in the request to send the current selected date "getChosenDate()".
        I used for the first fetch and it works but after that it does not get called anymore. It looks like onDateChanged does not get called.
        I tried to override the native methods next() and previous() but that does not work either.

        public void next(){
        setInitialCriteria(getFetchCriteria());
        fetchData(getFetchCriteria());
        super.next();
        }

        public void previous(){
        setInitialCriteria(getFetchCriteria());
        fetchData(getFetchCriteria());
        super.previous();
        }

        Or
        /**
        * Move to the next day, week, or month, depending on which tab is selected.
        */
        public native void next() /*-{
        var self = this.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
        self.fetchData(@com.db.am.dbinsight.web.dai.client.calendar.ExtendedCalendar::getFetchCriteria());
        self.next();
        }-*/;

        /**
        * Move to the previous day, week, or month, depending on which tab is selected.
        */
        public native void previous() /*-{
        var self = this.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
        self.fetchData(@com.db.am.dbinsight.web.dai.client.calendar.ExtendedCalendar::getFetchCriteria());
        self.previous();
        }-*/;


        If I set the setTotalRows to two pages by adding (endRow-startRow) to the record count it fetches twice at the beginning and stops fetching. This indicates that it tries to fetch all the records at once.

        I tried to get the next and previous buttons and then override their click method but that did not work.

        com.smartgwt.client.widgets.Button nextButton = (Button) com.smartgwt.client.widgets.Button.getById("daiCalendar_nextButton");
        nextButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
        setInitialCriteria(getFetchCriteria());
        fetchData(getFetchCriteria());

        }
        });

        Can anybody shed some light as to how to implement an actual paging on this component?

        Comment


          #5
          Adding a DateChangedHandler is the right approach, your next/previous hack won't work. If you believe there's a problem with this even not firing, please show a minimal modification of a Calendar sample demonstrating this, including listing out the actions you're taking in the UI such that you would expect the event to fire.

          Comment


            #6
            Yes, in did. This is the best way to page in calendar. I had an exception because I was casting the event to cancellable and trying to cancel before
            calling the fetch data. But now it all work.
            For those who stumble with this problem what I did is shown below.

            addDateChangedHandler(new DateChangedHandler() {

            @Override
            public void onDateChanged(DateChangedEvent event) {

            fetchData(getFetchCriteria(), new DSCallback() {

            @Override
            public void execute(DSResponse response, Object rawData, DSRequest request) {
            setData(response.getData());

            }
            });

            }
            });

            This method passes to the DMI the current selected date after the user clicks next, previous
            private Criteria getFetchCriteria(){
            Criteria cri = new Criteria();
            cri.addCriteria("selectedDate",getChosenDate());

            return cri;
            }

            Comment

            Working...
            X