|
[index.cshtml]
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowGrouping="true" height="315">
<e-grid-groupsettings captionTemplate="#captiontemplate" columns="@(new string[] {"CustomerID","ShipCountry"})"></e-grid-groupsettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="120"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="170"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script id="captiontemplate" type="text/x-template">
${customHelper(data)} ${if(count > 1)} <span class="validation">*</span> ${/if}
</script>
<style>
.validation {
color: red;
}
</style>
<script>
function customHelper(data){
// perform your actions here and return the data as you want
console.log(data)
return data.field + ": " + data.key + " - " + data.count;
}
</script>
|
Hi! Thanks for the assitance i seem to be able to somewhat solve the issue but i do have another question. In captiontemplate, what other attributes do we have other than ${field}, ${key} and ${count}? Is there any way for me to define my own variable in the script? I tried defining a variable called ${val} within the {$if()} statements but it becomes undefined in the view as shown below:
Script:
View:
If you dont mind, are there any references for these if else statements i am somewhat new to this. Any documentation related to operations in captiontemplate for Asp.net core would be greatly appreciated
Thanks for your assistance :)
|
[index.cshtml]
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowGrouping="true" height="315">
<e-grid-groupsettings captionTemplate="#captiontemplate" columns="@(new string[] {"CustomerID","ShipCountry"})"></e-grid-groupsettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="120"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="170"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script id="captiontemplate" type="text/x-template">
${customHelper(data)} ${if(count > 1)}
<span class="validation">*</span> ${/if}
</script>
<style>
.validation {
color: red;
}
</style>
<script>
var val = "customText";
function customHelper(data){
return data.field + ": " + data.key + " - " + data.count+ " "+ val; // return your customized text as you want which will be shown in Grid
}
</script>
|