Grid Missing Value

1 Answer 58 Views
Grid
Tim
Top achievements
Rank 3
Iron
Iron
Iron
Tim asked on 11 Sep 2024, 07:38 PM | edited on 11 Sep 2024, 07:57 PM

I have a grid that has first and last name columns. There are people whose last name is 'Null' (a STRING value, NOT the database/JSON value null). The last name cell is blank for these people. Is this a bug or a feature? Is there any way to configure the grid to display the actual value 'Null' instead of blank?

Here's part of the JSON:

        {
            "FirstName": "John",
            "LastName": "Null",
            "GradeValue": "2"
        },
        {
            "FirstName": "Jane",
            "LastName": "Null",
            "GradeValue": "2"
        },

1 Answer, 1 is accepted

Sort by
1
Accepted
Viktor Tachev
Telerik team
answered on 16 Sep 2024, 11:13 AM

Hi Tim,

By default if the value of a field is Null it will be interpreted as empty and not shown in the Grid component. However, if you would like to display a Null in a cell I suggest utilizing the template configuration for a column. The configuration for the LastName column would look similar to this:

columns.Bound(p => p.LastName).ClientTemplate("#=LastName==='Null'? 'Null' : LastName #");

 

Let me know how the suggested configuration works for you.

 

Regards,
Viktor Tachev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tim
Top achievements
Rank 3
Iron
Iron
Iron
commented on 16 Sep 2024, 11:05 PM

Hi Viktor,

That changes things, but I don't think the 'if' is being executed because it prints it without a capital 'N':

I have a content security policy, so I converted it to a function:


columns.Bound(x => x.LastName).ClientTemplateHandler("LastNameTemplateHandler");



function LastNameTemplateHandler(data) {
    if (data.LastName === 'Null') {
        return 'Null';
    }
    else {
        return data.LastName;
    }
}

Does it work for you?

Thanks,

Tim

Viktor Tachev
Telerik team
commented on 18 Sep 2024, 01:28 PM

Indeed using the if condition like this would display null with lower case 'n'. The reason being that, since in most cases null is a special value, internally the string "Null" will be converted to null. Thus, the first part of the if will never be true and the else option will be returned. 

In order to show Null with a capital "N" I suggest changing the template handler like this:

function LastNameTemplateHandler(data) {
    if (data.LastName === null) {
        return 'Null';
    }
    else {
        return data.LastName;
    }
}

Tim
Top achievements
Rank 3
Iron
Iron
Iron
commented on 18 Sep 2024, 08:44 PM

That works. Thank you for your help.
Tags
Grid
Asked by
Tim
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Viktor Tachev
Telerik team
Share this question
or