-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency Dropdown #71
Comments
Check out this issue and my answer to it #46 |
Its not about filtering of the records. For instance, there is The dropdown for insert and edit feature at 'team' should only show "x" and "y" when department "a" is selected, likewise, for department "b", only team"z" will be shown. Thanks for the reply! |
I see, you can extend this sample to |
How do i access the dropdown value of the previous column within the insertTemplate function? |
What if you implement it just the way it's implemented for |
I have tried however, I was experienceing some issues. I manage to filter out the teamField, however, whenever I tried to select on a single element in the team column, the insertControl onchange at department is still executing. insertcss: "department-filter",
insertTemplate: function() {
var teamField = this._grid.fields[2];
var $insertControl = jsGrid.fields.select.prototype.insertTemplate.call(this);
$insertControl.on("change", function() {
var selectedDepartment = $(this).val();
var departmentTeam = $.grep(team_list, function(team) {
return team.department === selectedDepartment;
});
alert("fe" + JSON.stringify(departmentTeam));
teamField.items = departmentTeam;
teamField.textField = "team";
teamField.valueField = "team";
$(".team-filter").empty().append(teamField.insertTemplate());
});
return $insertControl;
}, |
Could you modify the fiddle http://jsfiddle.net/tabalinas/n982uvx1/ to demonstrate the problem? |
Sorry for the late reply, this is the fiddle with the problem demonstrated, http://jsfiddle.net/n982uvx1/12/. As shown, the team does not show the list of team in the "team_list" despite having both valueField and textField set to "team". I have tried setting teamField.valueField = "team"; and teamField.textField = "team"; at the onchange function. However, as select upon the "team" dropdown list, the onchange function should trigger again and thus making it empty as a result. Thanks for your help! |
Everything looks correct, the only line with an error is: // the team field index is not 2 but 3
var teamField = this._grid.fields[3]; Here is the fiddle: http://jsfiddle.net/tabalinas/n982uvx1/13/ |
I see! Thanks alot! |
You are welcome! |
Sorry to bother again, for the fiddle as shown: http://jsfiddle.net/n982uvx1/14/ . Thanks! |
You should pass the argument of editTemplate: function(value) {
var teamField = this._grid.fields[3];
var $editControl = jsGrid.fields.select.prototype.editTemplate.call(this, value); Also for your scenario it would be better to set change handler to the select and call it immediately, like following: var changeDepartment = function() {
var selectedDepartment = $editControl.val();
var departmentTeam = $.grep(team_list, function(team) {
return team.department === selectedDepartment;
});
teamField.items = departmentTeam;
$(".team-edit").empty().append(teamField.editTemplate());
};
$editControl.on("change", changeDepartment);
changeDepartment(); You updated fiddle http://jsfiddle.net/tabalinas/n982uvx1/16/ |
var changeDepartment = function() {
var selectedType = $(".type-edit select").val();
var selectedDepartment = $editControl.val();
var departmentTeam = $.grep(team_list, function(team) {
return (team.department === selectedDepartment) && (team.type === selectedType);
});
teamField.items = departmentTeam;
$(".team-edit").empty().append(teamField.editTemplate());
}; Thanks alot for the help, however how do i access other access columns from the editTemplate? |
You can get the field from the grid by index and get it's edit control ( |
Hi tabalinas, |
The problem is when you have an item with team that is filtered by department, it cannot be found and rendered as empty. itemTemplate: function(team) {
return team;
}, Here is the fixed issue http://jsfiddle.net/n982uvx1/19/ In more general case we could grep team from entire list of teams (if we would use id, not the team name). |
Hi tabalinas, Here is the sample with valueField: "id" http://jsfiddle.net/n982uvx1/20/ Thank you |
Ok, that what I meant by comment "In more general case we could grep team from entire list of teams (if we would use id, not the team name)." Just modify itemTemplate: function(teamId) {
return $.grep(teams, function(team) {
return team.id === teamId;
}[0].name;
}, here |
Hi tabalinas, |
It's because in the |
Ok, now you can see the grid but when you try to edit or insert items there is the same error: Uncaught TypeError: Cannot read property 'team' of undefined. :S Thank you very much tabalinas!!! |
Ok, I fix it. On item "team" I put valueField:"Id" and when you edit or insert items take the id and when load the grid take the team... Thank you so much!!! |
Glad you found the solution. You are welcome! |
Hello Tabalinas, http://jsfiddle.net/n982uvx1/24/ Thank you |
It doesn't work because filtering is not implemented in the |
Ok, thanks!!! |
I have tried this example to populate States from selected Country dropdown. For some reason on insert, first record gets inserted correctly but second record onwards itemTemplate always receives 1 as function parameter resulting in incorrect state showing up on grid. Edit work fine though as on edit, itemTemplate is getting called only once. Below is my code; $("#lodgingJsGrid").jsGrid({
|
I have many data such as department, team, and group that i would need to filter them using dropdown.
I was able to populate the department dropdownlist with json, however, i wasnt able to retrieve the select department at the first column and use it as a key to filter the team value in the 2nd column and so on.
Any idea or help?
The text was updated successfully, but these errors were encountered: