Hi everyone!
i have a little problem, i made a kendo ui grid, and i added a Columns Template (checkbox), and agregates function, sum and avarage, it works perfectly.
but i wanna do the fallowing: the user will enable some checkbox , the grid has to refresh , i mean the agregate needs to recalculate again, when the user selects checkboxes.
so, i have 3 rows A , B , C. by default all are selected and agregate are calculated, but it happends that the user removes B, so the grid needs to recalculate de "sum" and "avarage" again for A and C.
this is my code so far: i wanna basicly wanna refresh my agregates with help of a checkbox. im using Kend ui with razor. any help will be super appriciate!
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Navigatable()
.Columns(columns =>
{
columns.Template(@<text>
<input name="LstModelSel" type="checkbox" title="LstModelSel" onclick="Refresh(@item.TotalOutstanding)" value="@item.ExposureNummer"
@if (Model.Any(p => p.ExposureNummer == item.ExposureNummer))
{
@("checked=checked")
}
/>
</text>)
.HeaderTemplate(@<text>
<input id="LstModelSel" type="checkbox" title="LstModelSel"
@if (Model.Any())
{
@("checked=checked")
}
onclick="return LstModelSel_onclick()" />
</text>)
.Width(50)
.HtmlAttributes(new { style = "text-align:center" })
.HeaderHtmlAttributes(new { style = "text-align:center" });
columns.Bound(p => p.ExposureNummer);
columns.Bound(p => p.GroupNummer);
columns.Bound(p => p.Name);
columns.Bound(p => p.TypeofLoan);
columns.Bound(p => p.TotalLimit);
columns.Bound(p => p.TotalOutstanding).GroupFooterTemplate((@<text> <div> Total: @item.Sum </div> <div> Average: @item.Average </div> </text>));
columns.Bound(p => p.ArpovalDate);
columns.Bound(p => p.Status);
columns.Bound(p => p.Rating);
columns.Bound(p => p.EL);
columns.Bound(p => p.LostProvision).GroupFooterTemplate((@<text> <div> Total: @item.Sum </div> <div> Average: @item.Average </div> </text>));
})
.Pageable()
//.Events(e => e.DataBound("Refresh()"))
.DataSource(dataSource => dataSource
.Server()
.PageSize(20)
.Aggregates(ListModel =>
{
ListModel.Add(p => p.TotalOutstanding).Average();
ListModel.Add(p => p.TotalOutstanding).Sum();
ListModel.Add(p => p.LostProvision).Average();
ListModel.Add(p => p.LostProvision).Sum();
})
.Group(groups => groups.Add(p => p.ExposureNummer)
)/*Agregates*/))
}
}
<script type="text/javascript">
$(document).ready(function () {
$('#LstModelSel').click(function () {
$("#Grid tbody input:checkbox").attr("checked", this.checked);
});
});
function Refresh(V) {
var sum = 0;
var val = V;
document.getElementById('re').value = val;
}
function LstModelSel_onclick() {
}
</script>
i have a little problem, i made a kendo ui grid, and i added a Columns Template (checkbox), and agregates function, sum and avarage, it works perfectly.
but i wanna do the fallowing: the user will enable some checkbox , the grid has to refresh , i mean the agregate needs to recalculate again, when the user selects checkboxes.
so, i have 3 rows A , B , C. by default all are selected and agregate are calculated, but it happends that the user removes B, so the grid needs to recalculate de "sum" and "avarage" again for A and C.
this is my code so far: i wanna basicly wanna refresh my agregates with help of a checkbox. im using Kend ui with razor. any help will be super appriciate!
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Navigatable()
.Columns(columns =>
{
columns.Template(@<text>
<input name="LstModelSel" type="checkbox" title="LstModelSel" onclick="Refresh(@item.TotalOutstanding)" value="@item.ExposureNummer"
@if (Model.Any(p => p.ExposureNummer == item.ExposureNummer))
{
@("checked=checked")
}
/>
</text>)
.HeaderTemplate(@<text>
<input id="LstModelSel" type="checkbox" title="LstModelSel"
@if (Model.Any())
{
@("checked=checked")
}
onclick="return LstModelSel_onclick()" />
</text>)
.Width(50)
.HtmlAttributes(new { style = "text-align:center" })
.HeaderHtmlAttributes(new { style = "text-align:center" });
columns.Bound(p => p.ExposureNummer);
columns.Bound(p => p.GroupNummer);
columns.Bound(p => p.Name);
columns.Bound(p => p.TypeofLoan);
columns.Bound(p => p.TotalLimit);
columns.Bound(p => p.TotalOutstanding).GroupFooterTemplate((@<text> <div> Total: @item.Sum </div> <div> Average: @item.Average </div> </text>));
columns.Bound(p => p.ArpovalDate);
columns.Bound(p => p.Status);
columns.Bound(p => p.Rating);
columns.Bound(p => p.EL);
columns.Bound(p => p.LostProvision).GroupFooterTemplate((@<text> <div> Total: @item.Sum </div> <div> Average: @item.Average </div> </text>));
})
.Pageable()
//.Events(e => e.DataBound("Refresh()"))
.DataSource(dataSource => dataSource
.Server()
.PageSize(20)
.Aggregates(ListModel =>
{
ListModel.Add(p => p.TotalOutstanding).Average();
ListModel.Add(p => p.TotalOutstanding).Sum();
ListModel.Add(p => p.LostProvision).Average();
ListModel.Add(p => p.LostProvision).Sum();
})
.Group(groups => groups.Add(p => p.ExposureNummer)
)/*Agregates*/))
}
}
<script type="text/javascript">
$(document).ready(function () {
$('#LstModelSel').click(function () {
$("#Grid tbody input:checkbox").attr("checked", this.checked);
});
});
function Refresh(V) {
var sum = 0;
var val = V;
document.getElementById('re').value = val;
}
function LstModelSel_onclick() {
}
</script>