Hi,
I have grouping in grid. In caption format I'd like to show text from some other fields.
For example, datasource has fields GroupID, GroupName, GroupDate, ItemID, ItemName and ItemAmount.
I'd like to have columns ItemName and ItemAmount grouped by GroupID. But in caption format of the group, I'd like to show GroupName and GroupDate for certain GroupID. How can I achieve that?
(we use EJ1)
|
<ej-grid id="FlatGrid"
allow-sorting="true" allow-grouping="true"
selectiontype="Multiple" datasource="(IEnumerable<object>)ViewBag.datasource" group-settings="@(new GroupSettings { CaptionFormat="#template" })" allow-paging="true" toolbar-click="click">
<e-columns>
…..
</ej-grid>
<script type="text/x-jsrender" id="template">
<span>
{{:~replaceText(#data['field'])}}
</span>
</script>
<script>
var helper = {
replaceText: function (field) {
var obj = $("#FlatGrid").ejGrid("instance");//create Grid Instance
var colIndex = obj.getColumnIndexByField(field)
var fieldnames = obj.getColumnFieldNames();
if (fieldnames.length == (colIndex+1)) {
return fieldnames[0];
}
else {
return fieldnames[colIndex + 1];
}
}
};//helpers
$.views.helpers(helper);
</script>
|
Hello,
thanks for answer.
Unfortunately, that's not exactly what I wanted.
I'd like to show the name of the group (= the value of field GroupName) for that GroupID, not the text "GroupID" itself.
On your example, that would be:
|
<ej-grid id="FlatGrid"
allow-sorting="true" allow-grouping="true"
selectiontype="Multiple" datasource="(IEnumerable<object>)ViewBag.datasource" group-settings="@(new GroupSettings { CaptionFormat="#template" })" allow-paging="true" toolbar-click="click">
<e-columns>
…..
</ej-grid>
<script type="text/x-jsrender" id="template">
<span>
{{:~replaceText(#data['field'], #data['key'])}} </span>
</script>
<script>
var helper = {
replaceText: function (field) {
var obj = $("#FlatGrid").ejGrid("instance");//create Grid Instance
var data = obj.model.dataSource;
for (var i = 0; i < data.length; i++) {
if (data[i].GroupID ==key) {
return data[i].GroupName;
}
}
};//helpers
$.views.helpers(helper);
</script>
|
Thanks, that's what I wanted.