This is a migrated thread and some comments may be shown as answers.

"Add new entry" errors with kendo.htmlEncode

1 Answer 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CS
Top achievements
Rank 2
CS asked on 02 Jun 2014, 01:07 PM

I'm experiencing some issues with the default "create" button to add a new empty row. Depending on what I enter for the grid column definition I get different htmlEncoding functions and they both fail.

 In the first case I use the complete object with a template for the field value, and in that function it should be encoded with at least data.Product, otherwise it will never be reachable because all the data is in data.
In the second case I tried only the value and this time I get at least a conditional on if it is null but it doesn't catch the case that Product might be null already.
Nullable option doesn't do anything to those.

Is there any way to get around this, since I'm unable to add new entries without errors.

schema: {
            model: {
                id: "ProductId",
                fields: {
                    Product    : { type: "object" , nullable: true}
                }
            }

columns: [
            {
                field   : "Product",
                title   : "Product",
                width   : 110,
                template: #=Product['Name']#
                }
            }

(function(data
/**/) {
    var o, e = kendo.htmlEncode;
    with (data) {
        o = '<tr class="k-alt" data-uid="' + (data.uid) + '" role=\'row\'><td  role=\'gridcell\'>' + (Product['Name']) + '</td><td  role=\'gridcell\'><a class="k-button k-button-icontext k-grid-edit"  href="#"><span class="k-icon k-edit"></span>Bearbeiten</a><a class="k-button k-button-icontext k-grid-Loeschen"  href="#"><span class=" "></span>Löschen</a></td></tr>';
    }
    return o;
})


columns: [
            {
                field   : "Product['Name']",
                title   : "Product",
                width   : 110
                }
            }


(function(data
/**/) {
    var o, e = kendo.htmlEncode;
    with (data) {
        o = '<tr class="k-alt" data-uid="' + (data.uid) + '" role=\'row\'><td  role=\'gridcell\'>' + e(data.Product['Name'] == null ? '' : data.Product['Name']) + '</td><td  role=\'gridcell\'><a class="k-button k-button-icontext k-grid-edit"  href="#"><span class="k-icon k-edit"></span>Bearbeiten</a><a class="k-button k-button-icontext k-grid-Loeschen"  href="#"><span class=" "></span>Löschen</a></td></tr>';
    }
    return o;
})






1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 04 Jun 2014, 11:22 AM
Hi Stefan,

You can include inline "if" statement inside the template which to be responsible for displaying the "Name" field only when it's available in current model - please check the example below:

columns: [{
        field: "Product",
        title: "Product",
        width: 110,
        template: "#=Product & Product.Name ? Product.Name : '- no product -'#"
    }
}

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
CS
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Share this question
or