I have the following piece of code which creates a cohortStore with a filter on cid.cid, or cohort id, is a foreign key to criteria table. The store is used to then construct an EditorGridPanel. When a user tries to add a new record to the table using the editorPanel, the cohort provides all of the cohort in the drop down option instead of the one that had been used in the filter. I tried adding an event to force the cid before the store is committed, but that does not work either. Please advice.
var cohortStore = new LABKEY.ext.Store({
schemaName: 'litterbox',
queryName: 'criteria',
columns: ['cohort', 'criterianame', 'criteriadescription','criteriasource'],
filterArray: [ LABKEY.Filter.create('cohort', cid, LABKEY.Filter.Types.EQUAL)],
sort: 'cohort'
});
// update cohort id to current cohort
cohortStore.on('beforecommit', function(records, rows) {
for ( var i = 0 ; i < records.length; i++ ) {
records[i].set('cohort', 5);
alert(records[i].get('cohort'));
}
return true;
});
var criteriaGrid = new LABKEY.ext.EditorGridPanel({
store: cohortStore,
width:800,
renderTo: 'criteriaList',
autoHeight: true,
title: 'Eligibility Criteria',
editable: true,
showExportButton: false,
autoSave: true
}); |
|
Ben Bimber responded: |
2012-01-20 04:57 |
hi maya,
the store you're editing controls which records will be shown in the grid. it sounds like you're referring the to combobox that is used as the editor for the cohort field. the editorgrid will get the metadata for each column in the table (it looks like litterbox.criteria in your case) and then render the appropriate column for this datatype. if the column has a lookup defined, it will create a combobox to use as the editor. this combo is backed by its own store, separate from the one you're manipulating.
with our current API, your best option is to check out the columnmodelcustomize event from EditorGridPanel. you'd use something like:
var criteriaGrid = new LABKEY.ext.EditorGridPanel({
store: cohortStore,
width:800,
renderTo: 'criteriaList',
autoHeight: true,
title: 'Eligibility Criteria',
editable: true,
showExportButton: false,
autoSave: true ,
listeners: {
scope: this,
columnmodelcustomize: function(columnModel, index)
{
//find your column of interest, then look for the editor property. change the store of this editor for one you create.
var editor = index[myColumnName].editor;
//change the store or replace the whole editor.
}
});
that code is just typed into the browser and untested, so there might be typos.
if you want or need more detail on changing the store for that combo, let me know.
another comment: instead of using alert() for debugging, use console.log(). it's less annoying, and you can actually write out objects. |
|
Maya Li responded: |
2012-01-20 09:48 |
Thanks, Ben. I changed the editor store and it worked pretty well. Also, thanks for the tip on using console.log. Great idea! |
|
|
|