Announcement

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

    Live Grid / fetching by scrolling, with JSON and Javascript

    To make my Application run smoother, I want to use the live-grid function as explained here: http://www.smartclient.com/docs/8.0/a/system/reference/SmartClient_Explorer.html#fetchOperation .
    I tried to use that code but it just loads everything at once when I load the page. I want it to load only the parts needed like in the example.

    I'm using Javascript and have a JSON-File with approximately 10'000 objects.

    #2
    try to use a RestDataSource: http://www.smartclient.com/docs/8.0/a/b/c/go.html#class..RestDataSource

    Comment


      #3
      Ok, thank you for your help so far.
      I tried to use the RestDataSource like this. The Source is a JSON-file, that looks similar to this code:

      Code:
      {    
          response:{
             status:0,
             startRow:0,
             endRow:20,
             totalRows:10000,
             data:[
                 {field1:"value", field2:"value"},
                 {field1:"value", field2:"value"},
                 ... 10'000 total records ...
             ]
          }
      }
      I create the RestDataSource like this

      Code:
      isc.RestDataSource.create({
          ID:         egui.customerSource.ID,
          dataURL:    egui.customerSource.dataURL,
          dataFormat: "json",
      });
      The good thing is, that it works but it just loads all the data at once, like I am using the normal DataSource. Can you tell me, what I am doing wrong, or how it should work? I had the idea, that I have to split the JSON-file somehow.

      Comment


        #4
        The data section of your json should only contain the data that matches the startRow and endRow. You shouldn't put in all 10,000 entries in there. When you scroll the grid, on the server side you should be able to read in the new startRow and endRow and send back the appropriate data

        Comment


          #5
          OK, I have to ask some silly questions for my understanding.

          1. Where does the startRow endRow status part come from. Is the RestDataSource creating it, or do I have to deliver it by myself in the JSON file.

          2. What must be set in the RestDataSource to deliver the data correctly?

          I think I've done things more complicated than I have to. Please help me!

          Comment


            #6
            To do livegrid paging, your server must accept the _startRow/_endRow parameters and return just the data requested. If you point any of the client data sources at a file you will not get paging.

            Take a look at the quickstart guide for details.

            Comment


              #7
              Here is a thread that might help http://forums.smartclient.com/showthread.php?t=16599

              On the server side, you extract from the client request the _startRow/_endRow, as davidj6 said, and you put into your json response only that slice of data. If you get your data from a MySql server, for example, you add to you statement:
              "limit "+_startRow+ ", "+(_endRow-_startRow).

              Comment

              Working...
              X