paging: 2nd page not working. - Ext JS

本文讨论了在使用ExtJS框架时遇到的问题:如何在分页操作中正确传递额外参数(如表名)到服务器端。作者分享了自己的代码实现,并通过社区交流找到了解决方案,包括设置`baseParams`来确保每次请求都包含必要的参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I hate to post what is no doubt something totally obvious, yet after going through the examples and forums I can't find a solution.

In my grid I have an extra parameter (table) that holds, obviously, the table name. This works fine for the first page, but when I use the paging toolbar this value is not sent. I've tried putting this parameter into the PagingToolbar but it doesn't ever seem to see it. Everything else works fine, if I hard code the table name then paging works fine, but I want it to be flexible. Can someone look at my code and tell me what I'm missing please.

//grid1.js 
var myGrid = function() { 
   return { 
      init: function() { 
         
         //we enable the QuickTips for the later Pagebar 
		Ext.QuickTips.init(); 

		// create the Data Store 
		var ds = new Ext.data.Store({ 
		   proxy: new Ext.data.HttpProxy({url: 'grid1_data.asp'}), 
		   reader: new Ext.data.JsonReader({ 
		      root: 'myFriends', 
		      totalProperty: 'totalCount', 
		      id: 'id' 
		   }, 
		   [ 
		   {name: 'ID', mapping: 'id', type: 'int'}, 
		   {name: 'Name', mapping: 'name', type: 'string'}, 
		   {name: 'Sector', mapping: 'sectorName', type: 'string'}
		   ]), 
		   // turn on remote sorting 
		   remoteSort: true 
		}); 
		//we set the deafault sort to the id ascending 
		ds.setDefaultSort('ID', 'asc'); 

		// now we create the Grid Columns 
		var cm = new Ext.grid.ColumnModel([ 
		   {header: "ID", dataIndex: 'ID', hidden:true}, 
		   {header: "Name", dataIndex: 'Name', width: 100, sortable: true}, 
		   {header: "Sector", dataIndex: 'Sector', width: 140, sortable: true}
		]); 
		// by default columns are sortable 
		cm.defaultSortable = true; 

		// create the grid 
		var grid = new Ext.grid.Grid('tutorial-grid', { 
		   ds: ds, 
		   cm: cm, 
		   selModel: new Ext.grid.RowSelectionModel({singleSelect:true}), 
		   enableColLock:true    
		}); 
		// render the Grid 
		grid.render();
		
		var gridFoot = grid.getView().getFooterPanel(true); 
		// add a paging toolbar to the grid's footer 
		var paging = new Ext.PagingToolbar(gridFoot, ds, {pageSize: 100});

		ds.load({params:{start:0, limit:100, table:'asset'}});
         
      } 
    }; 
}(); 
Ext.EventManager.onDocumentReady(myGrid.init, myGrid, true);
Unrelated, documentation question. As you can see from my code the ID field is hidden. I just guessed this value and it worked (hurrah for common sense). But I don't actually know where the different options for the columns are documented. I've gone through most of the grid documentation and I can't find it. width, renderer, sortable, resizable, locked, etc, etc it's easy enough to work them all out from the examples and such, but where are they in the documentation? I'm sure i'm missing something incredibly obvious...

Thanks.

Thanks.
Reply With Quote
  #2  
Old 03-15-2007, 01:30 PM
Default

The parameters in load are only used for that one load. Use ds.baseParams = {table: 'asset'} (either as given or in the config).
Reply With Quote
  #3  
Old 03-15-2007, 02:07 PM
Default

Attach a listener to the beforeload event for the datastore.

          ds.on('beforeload', function() {
            ds.baseParams = {
              sort: cm.getIndexById(ds.sortInfo.field) * ((ds.sortInfo.direction.toUpperCase() == 'DESC') ? -1 : 1)
            , search: search.getValue()
            };
          });
Reply With Quote
  #4  
Old 03-15-2007, 03:51 PM
Default

I did it this way (see "setFilter"). Mabye someone can comment on this if it is the wrong to do, but it works out quite well:
myGrid = function() {
    var grid; //grid itself
    var ds; // datastore

    return {
        init : function() {
...

        ds = new Ext.data.Store({
            // load a simple http proxy
            proxy: new Ext.data.HttpProxy({
                url: 'resp_calls.php'
            }),
            reader: reader,
            // turn on remote sorting
            remoteSort: true
        });
...
        }, // end init

        // pass over add. param for XHR request
        setFilter: function(afilter) {
          ds.baseParams = afilter;
          return true;
        }

  } // end return
}(); // endfunction myGrid
Usage:
myGrid.setFilter({table: 'asset'});
or///
myGrid.setFilter({table: 'asset', chair: 'asset2'});
Reply With Quote
  #5  
Old 03-15-2007, 07:04 PM
Default

Yes, that's certainly one way of doing it. It's important to understand that the baseParams aren't going to be dynamic (change, as needed, for every new XHR request that's generated for the grid), but each XHR request will use whatever state the baseParams is currently in.
Reply With Quote
我把日志级别改成了debug,首先权限,命令都是无问题,权限给的最高,命令我手动ssh登录控制台都可正常显示,也不会报错,但是这个程序命令执行在交换机后台日志看只正确了执行quit这条命令,其余都未执行,程序日志如下:2025-07-15 14:21:27,593 - DEBUG - read_channel: 2025-07-15 14:21:29,594 - DEBUG - read_channel: 2025-07-15 14:21:29,594 - DEBUG - write_channel: b'quit\n' 2025-07-15 14:21:29,594 - DEBUG - EOF in transport thread 2025-07-15 14:21:29,595 - INFO - 172.17.201.28 不是已知汇聚交换机,作为最终设备 2025-07-15 14:21:29,608 - DEBUG - starting thread (client mode): 0x7a64f2f0 2025-07-15 14:21:29,608 - DEBUG - Local version/idstring: SSH-2.0-paramiko_3.5.1 2025-07-15 14:21:29,609 - DEBUG - Remote version/idstring: SSH-1.99-Comware-5.20 2025-07-15 14:21:29,609 - INFO - Connected (version 1.99, client Comware-5.20) 2025-07-15 14:21:29,631 - DEBUG - === Key exchange possibilities === 2025-07-15 14:21:29,631 - DEBUG - kex algos: diffie-hellman-group-exchange-sha1, diffie-hellman-group14-sha1, diffie-hellman-group1-sha1 2025-07-15 14:21:29,631 - DEBUG - server key: ssh-rsa 2025-07-15 14:21:29,631 - DEBUG - client encrypt: aes128-cbc, 3des-cbc, des-cbc 2025-07-15 14:21:29,631 - DEBUG - server encrypt: aes128-cbc, 3des-cbc, des-cbc 2025-07-15 14:21:29,631 - DEBUG - client mac: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96 2025-07-15 14:21:29,631 - DEBUG - server mac: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96 2025-07-15 14:21:29,631 - DEBUG - client compress: none 2025-07-15 14:21:29,631 - DEBUG - server compress: none 2025-07-15 14:21:29,631 - DEBUG - client lang: <none> 2025-07-15 14:21:29,631 - DEBUG - server lang: <none> 2025-07-15 14:21:29,631 - DEBUG - kex follows: False 2025-07-15 14:21:29,631 - DEBUG - === Key exchange agreements === 2025-07-15 14:21:29,631 - DEBUG - Kex: diffie-hellman-group-exchange-sha1 2025-07-15 14:21:29,631 - DEBUG - HostKey: ssh-rsa 2025-07-15 14:21:29,631 - DEBUG - Cipher: aes128-cbc 2025-07-15 14:21:29,631 - DEBUG - MAC: hmac-sha1 2025-07-15 14:21:29,632 - DEBUG - Compression: none 2025-07-15 14:21:29,632 - DEBUG - === End of kex handshake === 2025-07-15 14:21:29,655 - DEBUG - Got server p (2048 bits) 2025-07-15 14:21:30,462 - DEBUG - kex engine KexGex specified hash_algo <built-in function openssl_sha1> 2025-07-15 14:21:30,462 - DEBUG - Switch to new keys ... 2025-07-15 14:21:30,463 - DEBUG - Adding ssh-rsa host key for 172.17.201.28: b'5e3ca5910d7cce29466ca9634fce6a23' 2025-07-15 14:21:30,486 - DEBUG - userauth is OK 2025-07-15 14:21:30,506 - INFO - Authentication (password) successful! 2025-07-15 14:21:30,507 - DEBUG - [chan 0] Max packet in: 32768 bytes 2025-07-15 14:21:30,528 - DEBUG - [chan 0] Max packet out: 32496 bytes 2025-07-15 14:21:30,528 - DEBUG - Secsh channel 0 opened. 2025-07-15 14:21:30,532 - DEBUG - [chan 0] Sesch channel 0 request ok 2025-07-15 14:21:30,536 - DEBUG - [chan 0] Sesch channel 0 request ok 2025-07-15 14:21:30,536 - DEBUG - write_channel: b'\n' 2025-07-15 14:21:30,638 - DEBUG - read_channel: ****************************************************************************** * Copyright (c) 2004-2013 Hangzhou H3C Tech. Co., Ltd. All rights reserved. * * Without the owner's prior written consent, * * no decompiling or reverse-engineering shall be allowed. * ****************************************************************************** <CDSL_SW201.28_LBG> 2025-07-15 14:21:30,638 - DEBUG - Pattern found: (to continue|[>\]]) ****************************************************************************** * Copyright (c) 2004-2013 Hangzhou H3C Tech. Co., Ltd. All rights reserved. * * Without the owner's prior written consent, * * no decompiling or reverse-engineering shall be allowed. * ****************************************************************************** <CDSL_SW201.28_LBG> 2025-07-15 14:21:30,939 - DEBUG - read_channel: <CDSL_SW201.28_LBG> 2025-07-15 14:21:30,939 - DEBUG - Clear buffer detects data in the channel 2025-07-15 14:21:31,540 - DEBUG - read_channel: 2025-07-15 14:21:31,540 - DEBUG - write_channel: b'\n' 2025-07-15 14:21:31,540 - DEBUG - read_channel: 2025-07-15 14:21:31,551 - DEBUG - read_channel: <CDSL_SW201.28_LBG> 2025-07-15 14:21:31,551 - DEBUG - Parenthesis found in pattern. pattern: (>|\]) This can be problemtic when used in read_until_pattern(). You should ensure that you use either non-capture groups i.e. '(?:' or that the parenthesis completely wrap the pattern '(pattern)' 2025-07-15 14:21:31,551 - DEBUG - Pattern found: (>|\]) <CDSL_SW201.28_LBG> 2025-07-15 14:21:31,852 - DEBUG - read_channel: 2025-07-15 14:21:31,852 - DEBUG - [find_prompt()]: prompt is <CDSL_SW201.28_LBG> 2025-07-15 14:21:31,852 - DEBUG - In disable_paging 2025-07-15 14:21:31,852 - DEBUG - Command: screen-length disable 2025-07-15 14:21:31,852 - DEBUG - write_channel: b'screen-length disable\n' 2025-07-15 14:21:31,852 - DEBUG - read_channel: 2025-07-15 14:21:31,863 - DEBUG - read_channel: s 2025-07-15 14:21:31,874 - DEBUG - read_channel: 2025-07-15 14:21:31,885 - DEBUG - read_channel: creen-length disable 2025-07-15 14:21:31,896 - DEBUG - read_channel: 2025-07-15 14:21:31,907 - DEBUG - read_channel: ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG> 2025-07-15 14:21:31,907 - DEBUG - Pattern found: (CDSL_SW201\.28_LBG) screen-length disable ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG 2025-07-15 14:21:31,907 - DEBUG - screen-length disable ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG 2025-07-15 14:21:31,907 - DEBUG - Exiting disable_paging 2025-07-15 14:21:31,907 - INFO - 成功连接 172.17.201.28 2025-07-15 14:21:31,907 - DEBUG - write_channel: b'screen-length disable\n' 2025-07-15 14:21:32,008 - DEBUG - read_channel: screen-length disable ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG> 2025-07-15 14:21:32,108 - DEBUG - read_channel: 2025-07-15 14:21:34,109 - DEBUG - read_channel: 2025-07-15 14:21:34,610 - DEBUG - write_channel: b'system-view\n' 2025-07-15 14:21:34,711 - DEBUG - read_channel: system-view ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG> 2025-07-15 14:21:34,812 - DEBUG - read_channel: 2025-07-15 14:21:36,813 - DEBUG - read_channel: 2025-07-15 14:21:37,814 - INFO - 172.17.201.28 是 H3C V5 交换机,使用特殊绑定流程 2025-07-15 14:21:37,814 - DEBUG - write_channel: b'display mac-address 6c0b-5e47-7f89\n' 2025-07-15 14:21:37,915 - DEBUG - read_channel: display mac-address 6c0b-5e47-7f89 ^ % Unrecognized command found at '^' position. <CDSL_SW201.28_LBG> 2025-07-15 14:21:38,016 - DEBUG - read_channel: 2025-07-15 14:21:40,018 - DEBUG - read_channel: 2025-07-15 14:21:40,018 - INFO - MAC地址查询结果: ^ % Unrecognized command found at '^' position. 2025-07-15 14:21:40,018 - ERROR - 在 172.17.201.28 上未找到 MAC 6c0b-5e47-7f89 对应的端口 2025-07-15 14:21:40,019 - DEBUG - write_channel: b'\n' 2025-07-15 14:21:40,120 - DEBUG - read_channel: <CDSL_SW201.28_LBG> 2025-07-15 14:21:40,221 - DEBUG - read_channel: 2025-07-15 14:21:42,222 - DEBUG - read_channel: 2025-07-15 14:21:42,222 - DEBUG - write_channel: b'quit\n' 2025-07-15 14:21:42,222 - DEBUG - EOF in transport thread
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值