Hi Customer,In the KB, Grid model where saved to the SQL Table in the DropDown change event. Can you please explain the scenario that you would like to save the state of the Grid Model to the Table? It would be helpful for us to provide you solution on this.Regards,Seeni Sakthi Kumar S.
<ej-grid [allowPaging]="true" id="Grid" [allowSorting]="true" [allowFiltering]="true" (resizeEnd) ="onResizeEnd($event)" (actionComplete)="onactionComplete($event)" [allowGrouping]="true" [allowResizing]="true" [allowReordering]="true" [dataSource]="gridData">
. . .
. . .
</ej-grid>
//Server end
public string Query(string gridObj)
{
con.Open();
var time = DateTime.Now.TimeOfDay.ToString();
//Inserting Grid object into StateStore Table with respective time
//States and CurrentTime are two columns in table
//States have the corresponding object whereas the CurrentTime as time
SqlCommand insert = new SqlCommand("INSERT INTO SaveModel (States,CurrentTime ) VALUES('" + gridObj + "','" + time + "')", con);
insert.ExecuteNonQuery();
con.Close();
return time;//can be saved in ejDropDownList
}
export class GridComponent {
public gridData: any;
onactionComplete(e) {
var gridObj = $("#Grid").ejGrid("instance")
this.stateChanges(e, gridObj);
};
onResizeEnd(e) {
var gridObj = $("#Grid").ejGrid("instance")
this.stateChanges(e, gridObj);
}
public stateChanges(args, proxy) {
if (args.requestType != "refresh") {
var columns = proxy.model.columns.slice();
if (args.type == "resizeEnd") {
. . .
. . .
columns[inx].width = args.newWidth;
}
var state = {
cols: columns,
groupedCol: proxy.model.groupSettings.groupedColumns.slice(),
sortedCol: proxy.model.sortSettings.sortedColumns.slice(),
filteredCol: proxy.model.filterSettings.filteredColumns.slice()
}
var object = JSON.stringify(state);//converting object to string
$.ajax({
type: "POST",
url: "http://localhost:50498/Home/Query",
data: { "gridObj": object },//posting the grid object as string
success: function (data, status, xhr) {
//On Success save the data which is the time
. . . .
},
});
}
}
}
|
appComponent.html
<ej-grid id="OrdersGrid" [dataSource]="gridData"[allowPaging]="true [editSettings]= "edit" [toolbarSettings]= "tool">
</ej-grid>
appComponent.ts
export class AppComponent {
public gridData = []
click(args) {
var obj = $("OrdersGrid").ejGrid("instance");
obj.dataSource(ej.DataManager({
adaptor : "UrlAdaptor"
}))
}
}
|
Hey,
With latest version not able anymore directly update grid state in this manner:
@ViewChild('myGrid') grid: EJComponents
Hello,
I prepared sample which is attached. Follow those steps:
No results will be loaded, because ejGrid shows only one filter set, but in reality - there are three. You can see that by checking ejGrid new get request :
Possible solution is to clear every filter before setting new state, but that is not an solution for large grid, as ejGrid will try to reload data after every filter reset - performance overload.
Any solutions?
P.S. After 'npm install' I updated Angular version to 'latest'.
private onLoadStateClicked(args)
{
// Getting grid widget
var grid = this.myGrid.widget;
// Creating state object
var state = JSON.parse(this.getStateString());
// Setting filters
grid.model.filterSettings.filteredColumns = state.filteredColumns.slice();
. . .
. .
grid._excelFilter._predicates = [];
// Refreshing columns
grid.columns(state.columns.slice());
console.log('State loaded with id: ' + this.dropDownListSelectedValue + ', state: ', state);
} |