<input type="button" value="Addrecord" onclick="myFunction()" />
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.PageSettings(page => page.PageSize(5))
.EditSettings(edit =>
{
edit.AllowAdding();//enebled adding
edit.AllowDeleting();//enabled deleting
edit.AllowEditing();//enabled editing
})
.Columns(col =>
{
col.Field("OrderID").IsPrimaryKey(true).Add();
col.Field("CustomerID").HeaderText("CustomerID").TextAlign(TextAlign.Left).Add();
col.Field("ShipCountry").HeaderText("Ship Country").TextAlign(TextAlign.Left).Add();
col.Field("EmployeeID").HeaderText("Employee ID").Add();
})
)
<script type="text/javascript">
var gridObj = $("#Grid").data("ejGrid");
// Sends an add new record request to the grid
gridObj.addRecord({"OrderID":12333});
</script> |
Hi,
I didn't understand. I wanna reload datasource, how can I do that, now I'm using the function on next, but the grid clear data em show no records.
$.ajax({
type: "POST",
url: '@Url.Action("LoadGrid", "Perfil")',
data: { "requiresCounts": true, "skip": 0, "take": 20, "params": {} },
dataType: "json",
success: function (result) {
var gridObj = $("#grid").data("ejGrid");
gridObj.dataSource(result);
},
error: function (result) {
alert("Erro");
}
});
Thanks.
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.Columns(col =>
{
. .
})
)
<script type="text/javascript">
function myFunction() {
var myKeyVals = { OrderID : 1, CustomerID : "FS", ShipCountry : "Canada", EmployeeID : 1 }
$.ajax({
url: "/Home/Insert",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: myKeyVals }),
success: function (data) {
var dataManager = ej.DataManager({
url : "/Home/DataSource",
adaptor : "UrlAdaptor"
})
$("#Grid").ejGrid("dataSource", dataManager);
alert("Save Complete")
},
error: function (xhr) {
alert('error');
}
});
}
</script>
|