Default Value for Columns

Default Value for Columns

davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

Trying to get default set to 0 if null.

columns: [{
                        "data": "emp_statement.month_year"
                    },
                    {
                        "data": "emp_statement.Employee"
                    },
                    {
                        "data": "emp_statement.Accessory_GP"
                    },
                    {
                        "data": "emp_statement.Diamond_Bundles"
                    },
                    {
                        "data": "emp_statement.Hum_X_on_DPP2"
                    },
                    {
                        "data": "emp_statement.Hum_on_2yr"
                    },
                    {
                        "data": "rm_emp_performance.Q_Postpaid_New"
                    },
                    {
                        "data": "emp_statement.New_Lines"
                    },
                    {
                        "data": "emp_statement.Pull_Through_22"
                    },
                    {
                        "data": "emp_statement.Smartphone_Box_Count_Target"
                    },
                    {
                        "data": "emp_statement.TMP_TMP_sold_Postpaid_Phones_including_CPE_Tablets"
                    },
                    {
                        "data": "emp_statement.Total_Gross_Profit"
                    },
                    {
                        "data": "emp_statement.Z4_Spiff"
                    },
                    {
                        "data": "emp_statement.Grand_Total"
                    },
                    {
                        "data": "emp_statement.detractor"
                    },
                    {
                        "data": "emp_statement.smb_ris"
                    },
                    {
                        "data": "emp_statement.aged",
                    },
                    {
                        "data": "emp_statement.chargebacks"
                    },
                    {
                        "data": "emp_statement.week1"
                    },
                    {
                        "data": "emp_statement.week2"
                    },
                    {
                        "data": null,
                        "title": "Total",
                        "render": function(data, type, row, meta) {
                            return row['emp_statement']['Grand_Total'] - row['emp_statement']['detractor'] + row['emp_statement']['aged'] - row['emp_statement']['chargebacks'] + row['emp_statement']['smb'];
                        },
                    }

I tried using

                    {
                        "data": "emp_statement.aged",
                        "defaultContent": "0"
                    },

This doesnt appear to work for me. I also removed the "" but still no go.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416

    You are already using a renderer for one of your fields. Just use the renderer to return 0 if data <= ““.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited August 2020 Answer ✓

    Trying to get default set to 0 if null.

    It works in this example:
    http://live.datatables.net/qebajula/1/edit

    The row with name One shows 0 in place of null. Row Two shows an empty cell as the the data is "". Row Three shows the value in the data of 3.

    Please update the test case to show a representation of the data you are having a problem with.

    Kevin

This discussion has been closed.