ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid - get Column list API
Title:
B
I
{code}
?
I am doing a "generic filter system", where indicating the field, the type of filter (greater than, less than, contains etc) and a value, creates the relative filter to pass to the service, so when I click a button "Add filter", I need to retrieve the columns of the grid I need to have a button that opens a popup where there is a dropdown filled with grid columns. is there a way to get the grid columns on the client ?
Save Changes
Cancel
Meccanica Rossi
asked at 23 Jan 2018
you can get the columns in js like this: $('#Grid1').data('o').columns
at 23 Jan 2018
Omu
OK Now run all ok, please last question : Is it possible retrive also the column datatype (int,string,date ecc) ? or maybe set extra info to a column ?
at 24 Jan 2018
Meccanica Rossi
The column has no type, the column mods are setting the `Tag` property for extra info, so if you will set `Tag = new {..}` and after call `.Mod` on the column the mod will replace your custom object.
at 24 Jan 2018
Omu
Thank you for very good support, now run ok ! Can I do the last question : I have a system where the user chooses the columns to display, but anyway in the grid data definition I have to put all the possible fields in the database and I'm afraid the process will slow down. therefore, for example, there may be a case that the user only displays 2 columns, while the table includes one hundred. the ideal would be that the definition of the grid reflects the fields chosen by the client, which of course are not known in advance Dou you think is possible ?
at 24 Jan 2018
Meccanica Rossi
var list = _userService.GetUserList(search); var gridModel = new GridModelBuilder<UserDto>(list.AsQueryable(), g) { Key = "Id", Map = o => new { o.Id, o.Name, o.FirstName, o.LastName, Date = o.CreatedOnUtc.ToShortDateString()}, // <- in this way fields are fix, can I choice fields with conditions ? }.Build();
at 24 Jan 2018
Meccanica Rossi
the slowdown is usually based on number of rows, not columns, anyway you should test that before making assumptions as for Map with condition Map = o => { if(a) return b; else return c; } or Map = o => { o.Id, Name = a ? null: o.Name, ...
at 24 Jan 2018
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK