Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: [Solved] store callback & records count

  1. #1

    Default [Solved] store callback & records count

    Im trying to get the count of the records in a store that is built as follows:
    Code:
     // readerDLLinks
       var readerDLLinks = new Ext.data.ArrayReader({}, [
        {name: 'dlid'},
        {name: 'dllink'},
        {name: 'dlname'}
        ]);
     // proxyDLLinks
     var proxyDLLinks = new Ext.data.HttpProxy({
      url: 'php/funcstf.php',
      method: 'POST'
     });
     // dsDLLinks
     var dsDLLinks = new Ext.data.Store({
      reader: readerDLLinks,
      proxy: proxyDLLinks
     });
    the data itself is returned from the php page as follows:
    Code:
    [["257","http://www.xyxyxyxy.com/forum/viewtopic.php?f=70&t=100731","Ghost Hunters International"],["2","http://www.xyxyxyxy.com/forum/viewtopic.php?f=70&t=124885","The Late Late Show with Craig Ferguson "],]
    and im loading the store as follows:
    Code:
    function fnDLSRefresh(btn) {
     if(btn == 'yes'){
      dsDLLinks.load({
       params : {action: 2},
       callback: function(records, options, success){
        alert(records[0].data.dlname);
       }
      });
     }
    };
    now i've tried:
    - alert(dsDLLinks.getCount()); ---- returns 0 always although there is data returned from the php page
    - alert(records.getCount()); ---- error
    finally i thought i would see if this "records" is reading anything by:
    - alert(records[0].data.dlname);
    which returns: records[0] is undefined

    i used the same method to load data into a grid (from reading an array into the datastore), but im stuck here..

    in short what i want to do is:
    1. get the returned records count
    2. will loop through that count and execute some AJAX request

    thank u all

  2. #2

    Default

    obviously there is something very stupid in my code that i can not notice and that everybody is just waiting for me to figure out

  3. #3
    Ext User Stripeman's Avatar
    Join Date
    Apr 2008
    Location
    Heidelberg Germany
    Posts
    275

    Default

    if i understand your question...this is normally done in your callback

    PHP Code:
    $query         $db_session->sqlQuery($dataQuery);              
    $nrows         $db_session->num_rows($query);
                
    while(
    $rec $db_session->fetch_array($query)) {                
           
    $arr[] = $rec;                
    };

    $data json_encode($arr);
    $_REQUEST['callback'].'({"total":"'.$nrows.'","results":'.$data.'})'
    and then in your store:

    PHP Code:
                var dataReader = new Ext.data.JsonReader({
                    
    root'results',
                    
    totalProperty'total'
                 
    },fields
                
    ); 

  4. #4
    Ext User Stripeman's Avatar
    Join Date
    Apr 2008
    Location
    Heidelberg Germany
    Posts
    275

    Default

    actually... i run two queries for the paging.. the first one to get the total number of records.. and the second for the paging total

    if you have questions about this let me know. I just didnt want to get off on another track.

  5. #5
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    try
    console.info(records.length);
    and for inspect
    console.dir(records);
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  6. #6

    Default

    Thanks all for your help (thanks Stripeman for your pointer) i was going all manual building the array in php (for some reason i thought it easier to do, which really doesn't make any sense) so i changed the way the array is built and changed the store to:
    Code:
     // dsDLMovies dataStore
     var dsDLLinks = new Ext.data.JsonStore({
      totalProperty: 'total', 
      root: 'results', 
      url: 'php/funcstf.php',    
      method: 'POST',
      fields: [
       {name: 'dlid', type: 'int'},
       'dllink', 'dlname'
      ]
     });
    and now the code works (im getting the first step which is the count back):
    Code:
    function fnDLSRefresh(btn) {
     if(btn == 'yes'){
      dsDLLinks.load({
       params : {action: 2},
       callback: function(records, options, success){
        alert(records.length);
       }
      });
     }
    };

  7. #7
    Ext User Stripeman's Avatar
    Join Date
    Apr 2008
    Location
    Heidelberg Germany
    Posts
    275

    Default

    glad u got it fingered out.

  8. #8

    Default

    here is the php code:
    Code:
    while(.....some condition){
       $arr[] = array('var1','var2','var3');
    }
     
    $data = json_encode($arr);
    $totaldata = sizeof($arr);
    echo '({"total":"'.$totaldata.'","results":'.$data.'})';
    instead of doing this, i was writting the array manually, and without the last echo with the total and results....like this:

    Code:
    echo "[";
    while(.....some condition){
       echo "[\"".$val[0]."\",\"".$val[1]."\",\"".$val[2]."\"],";
    }
    echo "]";
    plz, do not ask why i was doing it like this it's the only thing my grey cells could come up with at the time i wrote it

  9. #9
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    why so complicate?

    PHP Code:
    $return = array(
      
    'total' => count($arr),
      
    'results' => $arr
    );
    echo 
    json_encode($return); 
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  10. #10
    Ext User Stripeman's Avatar
    Join Date
    Apr 2008
    Location
    Heidelberg Germany
    Posts
    275

    Default

    Quote Originally Posted by amegahed View Post
    here is the php code:
    Code:
    while(.....some condition){
       $arr[] = array('var1','var2','var3');
    }
     
    $data = json_encode($arr);
    $totaldata = sizeof($arr);
    echo '({"total":"'.$totaldata.'","results":'.$data.'})';
    instead of doing this, i was writting the array manually, and without the last echo with the total and results....like this:

    Code:
    echo "[";
    while(.....some condition){
       echo "[\"".$val[0]."\",\"".$val[1]."\",\"".$val[2]."\"],";
    }
    echo "]";
    plz, do not ask why i was doing it like this it's the only thing my grey cells could come up with at the time i wrote it

    W.T.F. LOL

    The wonderful thing about using PHP (and other languages) with Ext is that it saves you so much time from spelling so much out...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •