Hi,
I have a simple grid and I would like to be able to store sorting, searching and filtering routines so a user clicks a button and it filters by Type, status and then orders by date created descending. The ideal goal is that the users can define and store their own and name it and then recall it by clicking a button at any time Is there a way to do that?
Cheers RJ
|
var persistData;
function onStore() {
var gridObj = document.getElementById('grid').ej2_instances[0];
persistData = JSON.parse(gridObj.getPersistData());
}
function onRestore() {
// Restores the entire stored settings to the Grid
gridObj.setProperties(persistData);
// Restores the stored filter properties to the Grid
gridObj.setProperties({ filterSettings: persistData.filterSettings });
} |
Hi,
Thanks for your response, I have tried this solution but when I debug the line persistData = JSON.parse... is always null! I am then trying to pass this grid data using an ajax call to my controller to save the data in my database... Have you any ideas? When I debug that line is always null and the ajax runs...
cheers,
RJ
Attachment: grid_(2)_b856e1fd.zip
Thanks for your reply,
I have managed to get this to work.
The
only thing I cant get working is I need to pass an extra string to the
controller. This is a string where the name the user wants to call this
grid current state. Can you help with how I could do this?
Also
I will want to store this state in an SQL table as I will recall this
from the database and then send it back to the grid. I was going to
serialize the Object then deserialize it to pass it back to the grid.
Cheers,
RJ
|
document.getElementById('select').addEventListener('click', function (args) {
var gridObj = document.getElementById('Grid').ej2_instances[0];
persistData = JSON.parse(gridObj.getPersistData());
persistData.stateName = 'NewStateName';
// Ajax post is sent with Grid’s selected records
var ajax = new ej.base.Ajax({
url: '/Home/GetPersistData',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(persistData),
successHandler: function (data) {
}
});
ajax.send();
}) |
|
public IActionResult GetPersistData([FromBody]PersistType data) {
return Json(new { result = data });
}
public class PersistType {
...
public string stateName { get; set; }
} |
Hi Thank you for your reply.
This has worked well for me!
I
have tried today on how to store this object PersistType in your sample
using entity framework and an sql database. I have tired serializing
the object and trying to store each component of the object as a string
but it doesn't work as a number of the attributes are the generic 'object' type which I had never used before. Can you offer any help? The model/table in
the database doesn't matter as it is only for storing these saved table
settings for recall to the front end. There will be 5 or so preset
options to filter by type that users can recall plus then user defined filtering options
Any help appreciated
Cheers RJ
Hi
so I have continued to look into making this work and I can't make it word when I try to serialize the JSON object that had been suggested to pass to my controller a lot of the data is lost?
Do you have any other suggestions on what to do or a different type of object to receive in the controller?
Cheers,
RJ
|
using System;
using Syncfusion.EJ2.Grids;
namespace EJ2Grid.Controllers
{
public class HomeController : Controller
{
public IActionResult GetPersistData([FromBody]PersistType data)
{
return Json(new { result = data });
}
public class PersistType
{
public int selectedRowIndex { get; set; }
public GridFilterSettings filterSettings { get; set; }
public GridGroupSettings groupSettings { get; set; }
public GridPageSettings pageSettings { get; set; }
public GridSearchSettings searchSettings { get; set; }
public GridSortSettings sortSettings { get; set; }
public List<GridColumn> columns { get; set; }
public string stateName { get; set; }
}
}
} |
Hi,
Thanks for your prompt reply!
I tried this again this afternoon and it didn't work for me. The data parameter as shown in the capture is null, even though when I debug the ajax or just the previous suggestion of using object typed attributes it did work... I have installed all the nugets as described, As I only want to store and retrieve these settings, and get the name supplied by the user, is it possible to maybe store the settings as a some other format in SQL rather than breaking the settings down into many parts?
Kind regards,
RJ
Hi So I tried again and this didnt work for me!
I have attached the snippets of code requested and it shows that the grid object is being parsed but doesnt get passed to the controller for some reason!
Cheers,
RJ