Viewing 1 post (of 1 total)
  • Author
    Posts
  • #113753
    edwardsmarkff
    Participant

    hello —

    there appears there is a bug in smart.exports.js 27.1.0 as well as earlier releases.

    When two “allowExport: false” statements are specified, it causes the following error:

    Uncaught TypeError: compareFunctions[i] is not a function
        at smart.export.js:2538:59
        at Array.sort (<anonymous>)
        at sortByMultipleColumns (smart.export.js:2536:28)
        at DataExporter.processGroupingInformation (smart.export.js:2557:13)
        at DataExporter.exportToPDF (smart.export.js:719:21)
        at DataExporter.exportData (smart.export.js:245:31)
        at Grid.exportData (smart.grid.export.js:1104:35)
        at Button.<anonymous> (transcription.html:1128:10)

    According to google-AI, the following fixes it: (starting at line 2536)

                    /***                            dataSource.sort(function (a, b) {
                    /***                                for (let i = 0; i < sortColumns.length; i++) {
                    /***                                    const result = compareFunctions[i](a[sortColumns[i]], b[sortColumns[i]]);
                    /***            
                    /***                                    if (result === 0) {
                    /***                                        if (sortColumns[i + 1]) {
                    /***                                            continue;
                    /***                                        }
                    /***                                        else if (a._index !== undefined) {
                    /***                                            // makes sorting stable
                    /***                                            return (a._index - b._index) * directionCoefficients[i];
                    /***                                        }
                    /***            
                    /***                                        return 0;
                    /***                                    }
                    /***            
                    /***                                    return result * directionCoefficients[i];
                    /***                                }
                    /***                            });
                    */
    
    dataSource.sort(function (a, b) {
        for (let i = 0; i < sortColumns.length; i++) {
            const compareFn = typeof compareFunctions[i] === 'function'
                ? compareFunctions[i]
                : function (valA, valB) {
                    if (valA === valB) {
                        return 0;
                    }
                    if (valA === null || valA === undefined) {
                        return -1;
                    }
                    if (valB === null || valB === undefined) {
                        return 1;
                    }
                    return String(valA).localeCompare(String(valB));
                };
    
            const result = compareFn(a[sortColumns[i]], b[sortColumns[i]]);
    
            if (result === 0) {
                if (sortColumns[i + 1]) {
                    continue;
                }
                else if (a._index !== undefined) {
                    // makes sorting stable
                    return (a._index - b._index) * directionCoefficients[i];
                }
    
                return 0;
            }
    
            return result * directionCoefficients[i];
        }
    });

    alternatively, i can patch my grid.exportData(‘pdf’) statement with the following:

    const grid = document.querySelector('smart-grid');
    
    // 1. Read the actual active grouped columns from grid.grouping.groupBy
    const savedGroups = (grid.grouping && Array.isArray(grid.grouping.groupBy))
        ? [...grid.grouping.groupBy]
        : [];
    
    // 2. Clear grouping using Smart Grid's native API
    if (typeof grid.clearGrouping === 'function') {
        grid.clearGrouping();
    } else if (grid.grouping) {
        grid.grouping.groupBy = [];
    }
    
    try {
        grid.exportData('pdf');
    } finally {
        // 3. Restore the original groups immediately after export
        savedGroups.forEach(field => {
            if (typeof grid.addGroup === 'function') {
                grid.addGroup(field);
            }
        });
    }

    since i want to use the compressed code, i will use the patch, unless your developers have a better suggestion.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.