Google App Maker中基于Cloud SQL视图的表格排序失效问题求助
Fix for Non-Working Table Sorting in Google App Maker with Cloud SQL View
Let's break down why your sorting isn't working and how to fix it:
Core Issues in Your Current Script
- You're overwriting the original query object: The
queryparameter passed to your script already contains the sorting information from the table's header clicks. But you're creating a new query withvar query = app.models.DRIVERS_LIST.newQuery();, which discards all the existing sorting data. - Hardcoded sorting statements: You have lines like
query.sorting.Name._ascending()in multiple branches, which force a fixed sort order and override any user-triggered sorting from the table.
Corrected Script
Replace your current code with this version, which preserves the table's sorting parameters while applying your filters:
// Get filter parameters from the query var status = query.parameters.Status; var operation = query.parameters.Operation; var local = query.parameters.Local; var concat = query.parameters.Concat; // Clear existing filters first to start fresh query.clearFilters(); // Apply status filter based on selection switch(status) { case 'Activos': query.filters.DoprEndDate._equals = null; break; case 'Inactivos': query.filters.DoprEndDate._notEquals = null; break; case 'Todos': // No filter needed, already cleared above break; default: query.filters.DoprEndDate._equals = null; } // Apply additional filters if parameters are set if (operation !== null) { query.filters.Operation._equals = operation; } if (local !== null) { query.filters.Local._equals = local; } if (concat !== null) { query.filters.concatAll._contains = concat; } // Return the modified query (preserves original sorting from table header clicks) return query.run();
Key Fixes Explained
- No new query creation: We use the existing
queryobject passed to the script, which retains the sorting direction/column from the table's header interaction. - Removed hardcoded sorting: All lines forcing
_ascending()are removed, letting the table's built-in sorting logic control the order. - Clean filter reset: We start with
query.clearFilters()to ensure we don't leave old filters in place, then apply our conditional filters on top.
Additional Notes
- Make sure all fields you're trying to sort on in the table are present in your Cloud SQL View and properly mapped in your App Maker model.
- If your View includes computed fields, ensure they are sortable in MySQL (most standard computed fields should work fine).
内容的提问来源于stack exchange,提问作者JingleBells
相关产品推荐
相关产品推荐

