1. #1
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default How to send the parameter for data loading?

    How to send the parameter for data loading?


    I have an editable table. I've made functions like loading data, cell editing, adding rows in different PHP scripts and it works. But now I'm trying to make it in one file. I've done so:
    PHP Code:
    $task NULL;
    if ( isset(
    $_POST['action'])){ 
        
    $task $_POST['action']; 

    if (
    $task == "LOAD") {
    Load();
    }
    switch(
    $task){
        case 
    "LOAD":
            
    Load();
            
    mysql_close($link);
            break;
        case 
    "EDIT":
            
    Edit();
            
    mysql_close($link);
            break;
        case 
    "ADD":
            
    Add();
            
    mysql_close($link);
            break;
        default: 
            echo 
    "{failure:true}";
            
    mysql_close($link);
            break;
            

    As a result, the table is displayed for a moment and then disappears.

    ExtJS code for loading table:

    Code:
    var itemsPerPage = 30; 
    var store = Ext.create('Ext.data.Store', {
    id:'test',
    autoLoad: true,
    autoSync: true,
    model: 'User',
    pageSize: itemsPerPage,
    proxy: {
    type: 'ajax',
    url: 'osnova.php',
    reader: {
    type: 'json',
    root: 'results',
    totalProperty: 'total'
    }
    }
    });
    
    store.load({
        params:{
            action: 'LOAD',
            start:0,
            limit: itemsPerPage
        }
    });
    Loading function in PHP file:

    PHP Code:
    function Load(){
        
    $num_result mysql_query ("SELECT * FROM table2") or die (mysql_error());
        
        
        
    $totaldata mysql_num_rows($num_result);
        
        
    $result=mysql_query ("SELECT * FROM table2 ORDER BY Number LIMIT ".$_POST['start'].", ".$_POST['limit']."") or die (mysql_error ());    
        
        
    $data = array();
        
        while (
    $row=mysql_fetch_object($result))
        {
            
    $data [] = $row;
        }
        echo 
    '({"total":"'.$totaldata.'","results":'.json_encode($data).'})';
        

    I think that the problem in this:
    Code:
    store.load({
        params:{
            action: 'LOAD',
            start:0,
            limit: itemsPerPage
        }
    });
    But I can't understand how to do right.

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Location
    indonesia
    Posts
    6
    Vote Rating
    1
    hendrisoni is on a distinguished road

      0  

    Default use an api config

    use an api config


    Code:
    var store = Ext.create('Ext.data.Store', {
        id : 'test',
        autoLoad : true,
        autoSync : true,
        model : 'User',
        pageSize : itemsPerPage,
        listeners : {
            beforeload : function(store, O) {
                store.getProxy(). p.extraParams['PARAM'] = '----';
    
    
            },
            scope : this
        },
        proxy : {
            type : 'ajax',
            url : 'osnova.php',
            reader : {
                type : 'json',
                root : 'results',
                totalProperty : 'total'
            }
        },
        api : {
            read : siteUrl+ '/LOAD',
            create : siteUrl+ '/ADD',
            update : siteUrl+ '/EDIT',
            destroy : siteUrl+ '/destroy'
        },
    
    
        writer : {
            type : 'json',
            root : 'data'
        }
    });

  3. #3
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default


    Thanks, I'll try

Thread Participants: 1