<div id = "ControlRegion">
@* create form *@
<form id="frmFilters" method="post">
<div class="row">
<input type="submit" class="btn btn-primary" />
</div>
</form>
@Html.EJ().Pivot().PivotGrid("PivotGrid1").EnableGroupingBar(true).ClientSideEvents(clientSideEvents => clientSideEvents.Load("onLoad")).DataSource(dataSource => dataSource.Rows(rows => { rows.FieldName("Country").FieldCaption("Country").Add(); rows.FieldName("State").FieldCaption("State").Add(); }).Columns(columns => { columns.FieldName("Product").FieldCaption("Product").Add(); }).Values(values => { values.FieldName("Amount").Add(); values.FieldName("Quantity").Add(); }).Filters(filters => { filters.FieldName("Date").FieldCaption("Date").Add(); }))
</div>
<script type="text/javascript">
$(document).ready(function () {
var pivot_dataset = [];
$("#frmFilters").submit(function (e) {
var form = $(this);
var url = '@(Url.Action("GetData", "PivotGrid"))';
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: url,
success: function (result) {
var pivot = $("#PivotGrid1").ejPivotGrid("instance");
pivot.model.dataSource.data = result;
pivot._load();
},
error: function (jqXHR, textStatus, errorThrown) {
alert("KO");
console.log(textStatus + ' ' + errorThrown);
}
});
e.preventDefault();//To privent page reload
});
})
</script> |
function onLoad(args) {
for (var i = 0; i < pivot_dataset.length; i++) {
var val = (pivot_dataset[i])["Date"]; // Select field to set desired date format.
val = new Date(val);
//ej.widgetBase.formatting("{0:" + DateTime format string + "}", value, localization);
pivot_dataset[i].Date = ej.widgetBase.formatting("{0:" + "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" + "}", val, "es-ES"); // To convert the date format as per the applied format string and localization.
}
args.model.dataSource.data = pivot_dataset;
}
|
Martin Rasovsky
Developer
|
COPS Financial
Systems s.r.o. |
T |
+42 (05) 11205278 |
Purkynova 127 |
M |
+420 605 219 155 |
|
612 00 Brno, Czech
Republic |
|||
Commercial register: 62913883
UID: CZ 62913883
Register court: Mĕstským soudem v
Praze
@Html.EJ().Pivot().PivotGrid("PivotGrid1").EnableGroupingBar(true).ClientSideEvents(clientSideEvents => clientSideEvents.Load("onLoad")).DataSource(dataSource => dataSource.Rows(rows => { rows.FieldName("Date").FieldCaption("Date").Add(); }).Columns(columns => { columns.FieldName("Product").FieldCaption("Product").Add(); }).Values(values => { values.FieldName("Amount").Add(); values.FieldName("Quantity").Add(); }).Filters(filters => { filters.FieldName("Country").FieldCaption("Country").Add(); })) |
function onLoad(args) {
args.model.dataSource.rows[0]["format"] = "date";
args.model.dataSource.rows[0]["formatString"] = "dd-MM-yyyy";
} |