$("#jsGrid").jsGrid({
controller: {
loadData: function(filter) {
var d = $.Deferred();
$.ajax({
url: "url",
dataType: "json",
data : filter,
}).done(function(response) {
d.resolve(response);
});
return d.promise();
},
},
fields: [
{ name: "project", items: [{"id" : 0, "name" : "test"}], valueField: "id", textField: "name", type: "select" }
]
});
json source:
{ "data" : [{"project" : test }], "project_items" : [{"id" : 1, "name" : "test" }] }
I want to change items in "project" fields after load table. Is it possibile ?
Have you tried to change it with fieldOption (http://js-grid.com/docs/#fieldoptionfieldnamefieldindex-optionname-optionvalue):
$("#grid").jsGrid("fieldOption", "projects", newItems)
thanks, it is work. But If I use 2 select objects - second select object resets selectedIndex after add $("#grid").jsGrid("fieldOption", "projects", newItems) to first select object although "filter" object exists
this solution works but it is very ugly
}).done(function(response) {
for ( var i in fields ) {
var f = fields[i];
$("#jsGrid").jsGrid("fieldOption", f, "items", response[ f ]);
}
for ( var t in filter ) {
if ( fields.indexOf(t) < 0 ) { continue; };
var arr = $("#jsGrid").jsGrid("fieldOption", t, "items" );
var fund = 0;
for ( var j in arr ) {
if ( arr[j].id == filter[t] ) { fund = parseInt(j); }
}
if (fund < 0 ) { continue };
$("#jsGrid").jsGrid("fieldOption", t, "selectedIndex", fund );
}
d.resolve(response);
});
How to restore value text field/filter { name: "title", width: 300, title: "title", type: "text" } ?
$("#jsGrid").jsGrid("fieldOption", "title", "value", "bbbf") not work :(
Changing an option in a field causes grid render. That's why current values of fields are cleared.
If you do the update right after grid load, then filter and other fields should be empty, no?
If you would provide more details about your use case, we could probably find an appropriate solution.
If you would provide more details about your use case, we could probably find an appropriate solution
For example I have 2 select filter. First filter have 2 values [A, B]. Second filter must be have 2 values [C, D] if first filter select value A, and must be have 2 values [E,F] if first filter select value B. First filter must be save selected value after refresh page. Your example is work perfect if second filter have constant values. But if second filter change values depend of first filter ...
Checkout the following issue https://github.com/tabalinas/jsgrid/issues/46
There is a jsfiddle. Also there are several links for other related issues.
Hello. Artem Tabalin
I wanna change options dynamically. for example after load data, if it have error, I want to show another load message not default options.
but, I read your comment on issue. and I really did, if changed options, jsGrid load data continuosly.
I want to know how to change load message(options) dynamically.
Thank you.
@Seolhun, not sure the issue clear. Please open a separate issue and provide more details (with code snippets) or even better a jsfiddle showing the problem.
Most helpful comment
Have you tried to change it with
fieldOption(http://js-grid.com/docs/#fieldoptionfieldnamefieldindex-optionname-optionvalue):