Announcement

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

    can't refresh ListGrid's data after operating database directly

    I created a ListGrid that bound a DataSource(serverType:sql) which loaded by using loadDS tag in my application. I want use RPCManager to send request to rpcHandler.jsp and refresh listGrid (through invoke listgrid.fetchData method in RPCManager callback).

    The problem is that when a new record inserted into database by using SQLDriver class, my listgrid component can't display new record.The only way to display the new record is to refresh whole page.

    How can I refresh the listgrid?
    Last edited by landofdreams; 31 Jan 2007, 04:11.

    #2
    this probleam fixed

    I found that there a ResultSet type variable in ListGrid component.After invoking invalidateCache method, all rows in this listgrid were removed and replaced as a string "Loading Data ..." , then all records displayed :)

    Code:
    //invalidateCache
    function getCallback(){
        listgrid.data.invalidateCache();
    }
    Another question, I don't want the listgrid remove existed rows and display loading string. I prefer automatically add new data to this listgrid like binary_data application demonstrated in SmartClient 5.51.

    How can I implement it?
    Last edited by landofdreams; 31 Jan 2007, 18:22.

    Comment


      #3
      The reason you're seeing the loading rows is that an explicit invalidateCache() call on the ResultSet will ask for a new set of rows from the server, and during that turnaround time, by default you'll see the loading message.

      It is possible to suppress this loading message, but a fundamentally better approach is to use the DataSource.addData() method to add the row to the SQL data-set.
      Something like this:

      Code:
      var ds = isc.DataSource.getDataSource("myDS");
      ds.addData({ID:100, title:"New Item", name:"newItem"});
      Using this API will ensure that any ListGrid bound to the same dataSource will automatically show the new row when it gets added to the data-set on the server.

      Will this work for you?
      If not - a little more information on your use-case could help us see what approach would work best for you.

      Thanks
      Isomorphic Software

      Comment


        #4
        I can't refresh ListGrid / DataSource Also, I am using RestDataSource

        I am removing data in database directly, then:

        ?????? invalidateCache() is undefined ????

        Evaluator: result of 'emailaccountslistdetailspane' (0ms):
        ListGrid{ID: "emailaccountslistdetailspane",
        fields: Array[4],
        dataSource: [RestDataSource ID:emailaccountmainlist],


        Evaluator: result of 'emailaccountslistdetailspane.data.invalidateCache()' (1ms):
        undef

        Comment


          #5
          Sorry, I found my source of problem,
          Need to do a fetchData first, so the ListGrid contains ResultSet
          then use ListGrid.data.invalidateCache()

          Comment


            #6
            Hello, I need to always fetch data from server, to populate a ListGrid, so i'm trying invalidateCache():
            Code:
            fetchPeriodi = function (record) {
                var data = listaPeriodi.getData();
                if (isc.isA.ResultSet(data)) {
                    // data.setCriteria({ nudoss: record.nudoss }); // doesn't work
                    data.invalidateCache();
                } else {
            	periodiDS.fetchData(
            			{ nudoss: record.nudoss },
            	                function (response, data, request) { 
            				        var rs = isc.ResultSet.create({
            				              dataSource: "periodiDS",
            				              allRows: data
            		                        });
            			                listaPeriodi.setData(rs);
            			} 
            		);
                }
            };
            listaPeriodi is a ListGrid and periodiDS is the Datasource.
            invalidateCache() triggers a new fetchData...but without criteria.
            What am I missing?

            Comment


              #7
              The commented-out call to setCriteria(), that's marked "doesn't work" - in what way doesn't it work? Do you see any difference in that exact code if you uncomment that line?

              Comment


                #8
                Just a further note - a ResultSet in fetchMode:"local" fetches without criteria and applies criteria locally. Your other codepath provides "allRows" which will switch a ResultSet into fetchMode:"local" automatically.

                Comment


                  #9
                  I'll step back to give you more details about what i'm trying to obtain. (I'm using Smartclient 7.0 beta LGPL).
                  Previously I was initializing the ListGrid "listaPeriodi" like this:
                  Code:
                  fetchPeriodi = function (record) {
                  		periodiDS.fetchData(
                  			{ nudoss: record.nudoss },
                  		        function (response, data, request) {
                  				                          listaPeriodi.setData(data);
                                                                                         }
                  					   );
                  }
                  the datasource is defined as:
                  Code:
                  listaPeriodi = isc.ListGridScelta.create({
                      ID: "listaPeriodi",
                      dataSource: "periodiDS",
                  	selectionChanged: "periodi.listaPeriodiChangeSelection(record, state)",
                      fields: [{name: "periodo", title: "Periodo di Budget"}, 
                      		 {name: "stato", title: "Stato"}, 
                      		 {name: "idPeriodo", showIf: "false"}]
                  });
                  This way, when the "nudoss" criteria changes, data is retrieved from server only the first time for every criteria value, otherwise the cached data is used.
                  And I understand that this is the intended behaviour.

                  now I want to retrieve data from server every time.
                  Correct me if I'm wrong, but I understand that I must invalidate the cache, and to call the invalidateCache method I need a ResultSet object.

                  With the line commented as "doesn't work", I saw no differences, there is a request to the server, but the "nudoss" parameter isn't available.

                  my most recent attempt is:
                  Code:
                  fetchPeriodi = function (record) {
                      var data = periodi.listaPeriodi.getData();
                      if (isc.isA.ResultSet(data)) {
                          data.setCriteria({ nudoss: record.nudoss });
                          data.invalidateCache();
                      } else {
                  		periodiDS.fetchData(
                  			{ nudoss: record.nudoss },
                  		        function (response, data, request) {
                  				        var rs = isc.ResultSet.create({
                  		         	              dataSource: "periodiDS",
                  				              criteria: { nudoss: record.nudoss },
                  				              useClientFiltering: false
                  			                });
                  			                listaPeriodi.setData(rs);
                  			} 
                  					);
                      }
                  };
                  but it doesn't work as I need, cached data is used after the first fetch (per every nudoss value).

                  Have you got a working example where I can clear my understanding?
                  Or a link to the docs?
                  Last edited by claudiobosticco; 15 Dec 2008, 05:21.

                  Comment


                    #10
                    It's not clear where the problem lies with your code, but is there a problem with the simpler approach: just use a ListGrid that has a DataSource, has fetchData() called on it with criteria, and calls invalidateCache() to refresh?

                    Comment


                      #11
                      Originally posted by Isomorphic
                      It's not clear where the problem lies with your code, but is there a problem with the simpler approach: just use a ListGrid that has a DataSource, has fetchData() called on it with criteria, and calls invalidateCache() to refresh?
                      well, I'm feeling dumb :-)
                      actually I tried that in my first attempt:
                      Code:
                      fetchPeriodi = function (record) {
                      	var dati = listaPeriodi.data;//getData();
                          if (isc.isA.ResultSet(dati)) {
                          	dati.setCriteria({ nudoss: record.nudoss });
                              dati.invalidateCache();
                          } else {
                      		periodiDS.fetchData(
                      				{ nudoss: record.nudoss },
                      			        function (response, data, request) {
                      					        listaPeriodi.setData(data);	        
                      					    }
                      					);
                          }
                      };
                      but listaPeriodi.data is not a resultSet.
                      If I try
                      listaPeriodi.data.invalidateCache();
                      I obtain a "property or method not supported" error.
                      And sorry, in my previous post I cut'n'pasted the grid definition instead of the datasource, which actually is:
                      Code:
                      periodi.periodiDS = isc.DataSource.create({
                          ID: "periodiDS",
                          dataURL: "../json/PeriodiPerScelta",
                          dataFormat: "json",
                          fields: [{type: "text", name: "periodo"}, 
                          		 {type: "text", name: "stato"}, 
                          		 {type: "text", name: "idPeriodo", hidden: true, primaryKey: "true"}] 
                      });

                      Comment


                        #12
                        So again, your code differs from the much simpler approach - call listGrid.fetchData() (your code calls dataSource.fetchData()) the first time, this will create listGrid.data as a ResultSet. Then call listGrid.data.invalidateCache() thereafter.

                        Comment


                          #13
                          it's a IE 6.0 specific problem ?

                          I already tried to call listGrid.fetchData()...but now I'm retrying with Firefox (3.0.5) and it works (triggers a new "server" fetch every time)!

                          but when I get back to my (mandatory) IE 6.0 (actually 6.0.2900.5512.xpsp_sp3_gdr.080814-1236) it doesn't get data from server!

                          I'm using Smartclient 7.0 beta LGPL

                          please let me know if you need more details.

                          Comment


                            #14
                            Those two browsers have different default behaviors with respect to caching. Your server is probably not setting HTTP headers that clearly indicate that the response is either cachable or not cachable and IE is deciding that it is, whereas Firefox is deciding that it's not. You want to add Cache-Control:No-Cache to the response to make it clear the response is not intended to be cached.

                            Comment


                              #15
                              Sorry for being late.
                              As usual, you're right, a simple Filter to set Cache-Control:no-cache did the trick!

                              Comment

                              Working...
                              X