justpy-org / justpy

An object oriented high-level Python Web Framework that requires no frontend programming
https://justpy.io
Apache License 2.0
1.22k stars 96 forks source link

How to custom sorting ag-grid? #376

Closed ducnva closed 2 years ago

ducnva commented 2 years ago

Hi there, Thank you for this excellent library. I used justpy for my project. I have problem when I custom sorting, I add attr 'comparator' but when run code, it notify '...comparator is not function'. Can anyone help me?

import justpy as jp

grid_options = {
    'getDataPath': '''function(data) { return data.orgHierarchy; }''',
    'treeData': True,
    'defaultColDef': {
        'filter': True,
        'sortable': True,
        'resizable': True,
    },
    'columnDefs': [
        {'headerName': "job title", 'field': "jobTitle"},
        {'headerName': "employment type", 
         'field': "employmentType", 
        'comparator': '''function(valueA, valueB) {
            console.log('valuea', valueA)
                if (valueA == valueB) return 0;
                return (valueA > valueB) ? 1 : -1;
        }'''
        },
    ],
    'rowData' : [
        {'orgHierarchy': ['Erica'], 'jobTitle': "CEO", 'employmentType': "1"},
        {'orgHierarchy': ['Erica', 'Malcolm'], 'jobTitle': "VP", 'employmentType': "2"},
        {'orgHierarchy': ['Erica', 'Bob'], 'jobTitle': "SVP", 'employmentType': "3"},
        {'orgHierarchy': ['Erica', 'Bob', 'jo'], 'jobTitle': "eVP", 'employmentType': "4"}
    ]
}

def grid_test():
    wp = jp.WebPage()
    grid = jp.AgGrid(a=wp, options=grid_options)
    print(grid)
    grid.evaluate = ['getDataPath']
    return wp

jp.justpy(grid_test)