- Home
- Forum
- ASP.NET MVC - EJ 2
- How to make Grid properties permanent
How to make Grid properties permanent
- Are you use any custom actions for Reordering, Resizing etc.
- Share your code example.
- Please reproduce the issue in the given sample.
- Please share your Essential JavaScript 2 package version.
When the search button is clicked for the 2nd time (after column reordering, etc has been done) the page will ‘post back’ while it fetches new data from the database.
It is at this time that the grid no longer shows the altered column ordering. It goes back to the way the grid was when the page first initialized.
So, how do we get the grid attributes to stick between post backs? Thanks.
Hopefully, this will better articulate the problem
We are using your sync fusion grid
- The web page allows user to enter search data into a text box, user clicks a button and the grid gets populated from the database query – returns 100 rows.
- The user then filters the grid data by using the ‘excel’ like column header filters and reduces the grid lines shown down to 20
- We now want to get the data that is currently displayed in the grid (20 rows) into a popup window and run calculations on it or populate your Scatter Chart with the 20 rows of data
How can this be done since the data in the grid is being filtered by javascript/client side ?
|
<div>
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Columns(col =>
{
. . .
}).AllowPaging().AllowReordering().ActionComplete("complete").AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel)).AllowResizing(true).ShowColumnChooser(true).Toolbar(new List<string>() { "Search", "ColumnChooser" }).PageSettings(page => page.PageSize(10)).Render()
</div>
<script>
function complete(e) {
if (e.requestType == 'filtering') {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]
console.log(grid.currentViewData); // you can make your calculations on this current view data
}
}
</script> |
You are telling us to enable property: ActionComplete("complete").
That property doesn’t exist in our release - Syncfusion.EJ 16.1450.0.24
ssembly Syncfusion.EJ.MVC, Version=16.1500.0.24, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89
namespace Syncfusion.MVC.EJ
Don’t see any references to EJ2
Grid wrapper is:
@(Html.EJ().Grid<TechForJusticeLib.Domain.SentencingCase>("Grid")
|
@Html.EJ().Button("button").Text("Filtered Records").ClientSideEvents(e => e.Click("btnClick")) @(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.URL("DataSource").UpdateURL("UrlUpdate").InsertURL("UrlInsert").RemoveURL("UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.AllowFiltering()
.AllowReordering()
.AllowResizing()
.AllowSearching()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.Columns(col =>
{
……………….
}))
</div> <script> function btnClick(args) {
var gridObj = $("#FlatGrid").ejGrid("instance");
console.log(gridObj.getFilteredRecords());
}
</script> |
|
@Html.EJ().Button("button").Text("Filtered Records").ClientSideEvents(e => e.Click("btnClick")) <div id="ControlRegion"> @(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.URL("DataSource").UpdateURL("UrlUpdate").InsertURL("UrlInsert").RemoveURL("UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.AllowFiltering()
.AllowReordering()
.AllowResizing()
.AllowSearching()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.ClientSideEvents(eve => { eve.ActionComplete("actionComplete"); }) .Columns(col =>
{
………..
}))
</div> <script type="text/javascript"> function btnClick(args) {
var obj = $('#FlatGrid').ejGrid("instance");
var data = obj.getFilteredRecords();
$.ajax({
type: "POST",
url: "/Grid/Data",
datatype: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ gridFilteredData: JSON.stringify(data) }),
success: function (result) {
alert('success');
},
error: function (args) {
alert('error occurred');
}
});
}
</script> controllerPage:
public ActionResult Data(string gridFilteredData)
{
// You can do your stuff here return Json (gridFilteredData);
} |
|
@(Html.EJ().Grid<object>("Grid")
.ClientSideEvents(eve =>
{
eve.Load("Onload");
})
}))
<script>
function Onload(args){
var gridObj = $("#Grid").ejGrid("instance");
//To retrieve the Grid objects
$.ajax({
type: "POST",
url: "/Home/Restate",
success: function (data) {
var obj = JSON.parse(data);
gridObj.model.groupSettings.groupedColumns = obj.groupedCol;
if (obj.cols)
gridObj.columns(obj.cols);
else
gridObj.refreshContent();//Refresh the Grid to apply the saved settings
//if you are using anyother Grid methods to refresh other functionlities
//like columns()
//there is no need of refreshContent()
},
});
}
</script>
|
|
<div>
@Html.EJS().Button("printbtn").Content("Save").IsPrimary(true).Render()
@Html.EJS().Grid("Grid").Load("load").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Width("150").Add();
col.Field("Freight").HeaderText("Freight").Width("170").Add();
}).AllowPaging().AllowReordering().Render()
</div>
<script>
document.getElementById('printbtn').onclick = function () {
// save the column values in server
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]
var ajaxObj = new ej.base.Ajax();
ajaxObj.type = 'POST';
ajaxObj.contentType = 'application/json';
ajaxObj.url = '/Home/CheckState';
// stringify the column values
ajaxObj.send(JSON.stringify({ 'data': JSON.stringify(grid.columns) })).then(function (value) {
console.log(JSON.parse(value));
});
}
function load() {
var persistColumns = @Html.Raw(Json.Encode(ViewBag.columns));
if (JSON.parse(persistColumns)) {
this.columns = JSON.parse(persistColumns);
}
}
</script> |
|
public ActionResult Index()
{
ViewBag.columns = columns;
return View();
}
public static string columns;
public ActionResult UrlDatasource(Data dm)
{
var order = OrdersDetails.GetAllRecords();
var Data = order.ToList();
int count = order.Count();
return dm.requiresCounts ? Data.Count!= 0 ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }): Json(Data) : Json(Data);
}
public ActionResult CheckState(string data)
{
columns = data;
return Content(data);
} |
|
<div>
@Html.EJS().Button("printbtn").Content("Save").IsPrimary(true).Render()
@Html.EJS().Grid("Grid").Load("load").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Width("150").Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
col.Field("Freight").HeaderText("Freight").Width("170").Add();
col.Field("ShipName").HeaderText("Ship Name").Width("170").Add();
col.Field("ShipAddress").HeaderText("Ship Address").Width("170").Add();
}).AllowPaging().AllowReordering().Render()
</div> |
|
<script>
function load() {
var persistColumns = @Html.Raw(Json.Encode(ViewBag.columns));
if (JSON.parse(persistColumns)) {
var position = [5, 2, 3, 1, 4]; // saved index value
var dummy = [];
position.forEach((value, index, array) => {
dummy[value - 1] = this.columns[index];
});
this.columns = dummy;
}
</script> |
|
|
R.Dhivya
- 16 Replies
- 4 Participants
-
BU Buster
- May 13, 2018 06:33 PM UTC
- Jul 9, 2018 12:27 PM UTC