PDA

View Full Version : Combo used in grid with store loaded using filter value from existing grid row?



nickweavers
25 Mar 2011, 2:28 AM
I have a grid that allows entry of job assignments for an event at a future date shown here
http://www.achilleus.co.uk/sencha_forum_images/assignment_grid.jpg
For each row that is created, a job role must be selected from a combo that appears in the Job Title column (when clicked) to state what job the particular assignment is for. The assignments are automatically posted up on another form elsewhere on the website ("front end") where employees, can indicate their availability to work on them using a checkbox against each one. Their employee id and assignment id are captured and recorded.

At some time nearer the date of the event, admin staff need to choose suitable employees for the assignments. This is to be done using combo boxes in the third column shown here http://www.achilleus.co.uk/sencha_forum_images/employee_combo.jpg.
The server side php that provides the data when the store loads must be passed the event date and job role. It can then do a query against the database tables to get a list of employees who are available on that date, and who have that job role as their job title.

I am having trouble figuring out how to accomplish this. Initially, I was thinking that I would need to use the beforeload event on the employeeComboStore to fill an employeeCombo when it was clicked as follows:


// -------------------------------------------------------------------------------------
// Add event_date as a baseParm for employeeComboStore, assigning the
// value obtained from the currently selected record in the
// bookingSelectorGrid sm
// -------------------------------------------------------------------------------------
<?php echo $ns; ?>.employeeComboStore.on('beforeload', function (employeeComboStore, options) {
var bs_sm_record = <?php echo $ns; ?>.bookingSelectorGrid.getSelectionModel().getSelected();
var as_sm_record = <?php echo $ns; ?>.assignmentGrid.getSelectionModel().getSelected();
employeeComboStore.setBaseParam('event_date',bs_sm_record.data.event_date);
employeeComboStore.setBaseParam('job_title',as_sm_record.data.job_title);
});

but this gives me an error "assignmentGrid.getSelectionModel().getSelected is not a function" when the grid loads, since at that point no row is selected.

Can anyone suggest a good strategy for what I am trying to do?

TIA.

conorarmstrong
25 Mar 2011, 3:47 AM
What about selecting that row in a beforeedit event listener on the editorgridpanel eg


listeners: {

<snip>

beforeedit: function(e) {
e.grid.getSelectionModel().selectRow(e.row);
}

<snip>

}

nickweavers
28 Mar 2011, 5:59 AM
Thanks conorarmstrong, that was a good idea and I used it like this:


listeners: {
beforeedit: function(e) {
// For each cell that gets edited, check to see if it is the employee
// field. If it is, load the employeeCombo passing it the
// assignment ID
if (e.field == 'id_employee') {
var id_assignment = e.record.data.id_assignment;
<?php echo $ns; ?>.employeeComboStore.load({
params: {
id_assignment: id_assignment
}
});
}
},

Seems to work okay (so far).