You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. You're overwriting the original query object: The query parameter passed to your script already contains the sorting information from the table's header clicks. But you're creating a new query with var query = app.models.DRIVERS_LIST.newQuery();, which discards all the existing sorting data.
  2. 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 query object 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:29:24