开发平台:asp.net core2.1
请教一下flexgrid的sourceCollection绑定返回的json数据后,按下header的时候,绑定的数据又消失了,通过调试发现按下header的时候它又重新跑了一遍一下的代码,public ActionResult Index() {
return View();
}
要怎么设定才能让绑定的数据不消失进行正常排序呢?
<script type="text/javascript">
function parseDate(strDate) {
var date = strDate.match(/\d+/g);
return new Date(parseInt(date));
}
function btn1_click() {
$.ajax({
type: "POST",
url: "/Home/GetData",
dataType: "json",
data: { count: 10 },
success: function (result) {
var flex = wijmo.Control.getControl("#gFlexGrid"),
cv = flex.collectionView;
//flex.itemsSource = result;
try {
cv._isFillingData = true;
cv.deferUpdate(function () {
cv.sourceCollection.clear();
result.forEach(function (item) {
item.Start = parseDate(item.Start);
item.End = parseDate(item.End);
cv.sourceCollection.push(item);
});
})
} finally {
cv._isFillingData = false;
}
},
error: function (err) {
}
});
}
function btn_save_click() {
var flex = wijmo.Control.getControl("#gFlexGrid"),
cv = flex.collectionView;
cv.commit();
}
</script>
<div>
<div>
<input type="button" id="btn1" value="Get Data" />
<input type="button" id="btn_save" value="Save Data" />
</div>
<h4>FlexGrid - Image in Cells</h4>
@(Html.C1().FlexGrid()
.Id("gFlexGrid")
.AutoGenerateColumns(false)
.IsReadOnly(true)
.AutoClipboard(true)
.AllowSorting(true)
.AllowAddNew(false)
.SelectionMode(C1.Web.Mvc.Grid.SelectionMode.Row)
.Height(500)
.CssClass("grid")
.Columns(bl =>
{
bl.Add(cb => cb.Binding("ID").Width("0.4*"));
bl.Add(cb => cb.Binding("Country").Header("Country").Width("*").Name("Country"));
bl.Add(cb => cb.Binding("Amount").Header("Amount").Width("*").Name("Amount"));
bl.Add(cb => cb.Binding("Product").Header("Product").Width("*").Name("Product"));
})
)
</div>
[HttpPost]
public JsonResult GetData(int count)
{
List<Sale> saleList = Sale.GetData(count).ToList<Sale>();
return Json(saleList);
}
|
|