ExtJS 4如何导出表格前两页数据?现有功能仅导出第一页求解决
Hey there, let's tackle this issue you're facing with ExtJS 4 Excel export only grabbing the first page of data. The root cause here is that your current export logic is probably pulling data from the rendered DOM elements of the grid (which only show the current page) instead of accessing the full dataset from your Store. Here are a few solid solutions:
1. Pull Full Data Directly from the Store
Instead of using methods that fetch rows from the grid's view (like getView().getNodes()), tap into the Store's full dataset with getRange():
// Grab ALL records from the grid's Store var allRecords = yourGrid.getStore().getRange(); // Convert these records into the format your export function expects // (this replaces whatever logic you were using to pull visible rows)
This works regardless of the current page, since getRange() returns every record the Store holds.
2. Temporarily Disable Pagination for Export
If your export logic relies on the grid's rendered content, you can temporarily disable pagination, load all data, export, then revert back:
var gridStore = yourGrid.getStore(); // Save current pagination settings to restore later var originalPageSize = gridStore.pageSize; var currentPage = gridStore.currentPage; // Load all data by setting pageSize to total record count gridStore.pageSize = gridStore.getTotalCount(); gridStore.loadPage(1, { callback: function(records, operation, success) { if (success) { // Run your existing export function now that all rows are rendered yourExcelExportFunction(yourGrid); // Restore original pagination gridStore.pageSize = originalPageSize; gridStore.loadPage(currentPage); } } });
Note: This only works if your Store has access to all records (i.e., not server-side pagination where only the current page is loaded).
3. Check Your Export Tool's Configuration
If you're using a third-party export plugin (like Ext.ux.Exporter), look for a setting like exportAllData and make sure it's enabled:
var exporter = Ext.create('Ext.ux.Exporter', { exportAllData: true, // Critical for full dataset export // Other export configs (like file type, columns, etc.) }); exporter.exportGrid(yourGrid);
Special Case: Server-Side Pagination
If your grid uses server-side pagination (where the backend only sends one page at a time), you'll need to:
- Either call a dedicated backend endpoint that returns all records for export
- Or modify your existing endpoint to accept a flag (like
exportMode=true) that skips pagination and returns full data
内容的提问来源于stack exchange,提问作者Jagan Akash

