Regular Table

Below is an example configuration of a panel using the Table module:

{
    "title": "EDB Risk Calculation",
    "width": 12,
    "full_row": True,
    "reload_div": True,
    "url_name": "frame_regular_table",
    "url_action_name": "edb_test",
    "content": {
        "view": custom_views.RegularTableEdbCalculation,
        "view_params": {
            "limit": 1000,  # TODO remove
            "model": custom_models.EdbCalculation,
            "order_by": "supplier__name",
            "row_style_function": custom_functions.row_style_function_monitoring_status,
            "field_definitions": {
                # Product related
                "supplier__link": {
                    "label": "Factory/Facility Name",
                    "format": "text_link",
                },
                "supplier__location__country": {
                    "label": "Country",
                },
                "supplier__facility_state": {
                    "label": "State/Province",
                },
                "raw_material": {
                    "label": "Raw Material",
                },
                "social_and_labor": {
                    "label": "Social & Labor Score",
                    "format": "intcomma_rounding2",
                },
                "health_and_safety": {
                    "label": "Health & Safety Score",
                    "format": "intcomma_rounding2",
                },
                "environment": {
                    "label": "Environmental Score",
                    "format": "intcomma_rounding2",
                },
                "is_screened": {
                    "label": "Is Screened",
                    "format": "boolean",
                },
                "flag_score": {
                    "label": "Supplier Screening Flag Score = 10 if no issue = 0 otherwise",
                    "format": "intcomma_rounding2",
                },
                "supplier__issue_list_elevate": {
                    "label": "Issues Flagged by Elevate"
                },
                "supplier__issue_list_kharon": {
                    "label": "Issues Flagged by Kharon",
                },
                "supplier__issue_list_dowjones": {
                    "label": "Issues Flagged by Dow Jones",
                },
                "total_risk_exposure_score": {
                    "label": "Total Safety Score",
                    "format": "intcomma_rounding2",
                },
            },
        },
    },
},

The view_params are:

  • model the model this table is based on

  • order_by the model field (str) or fields (list) to order the table by when loading (by default ascending alphanumeric order, for descending order use the prefix "-" (e.g. "-id"))

  • is_empty sets whether the table should be empty by default until the user clicks the Search button (must have a selectpickers section on top of the page)

  • init_max_rows_threshold the maximum number of rows that will be displayed without the user clicking the Search button

  • table_settings the table-level configuration

  • field_definition column showed in the table from the model

  • limit: The maximum number of rows showed in the table

Since it is using the custom_views, the custom_views can be defined as followed:


class RegularTableEdbCalculation(module_views.RegularTable):
    def get_cell_style(self, field_name, value, item):
        if field_name in [
            "social_and_labor",
            "health_and_safety",
            "environment",
            "total_risk_exposure_score",
        ]:
            if value < 3:
                return "color: #FF8463;"
            elif value < 6:
                return "color: #FFC863;"
            else:
                return "color: #63FF63;"

The regular table can have colors in some field in the regular table.

Last updated