问题
I am working with IBM Content Navigator 2.0.3, that uses DOJO 1.8 for the GUI development. I am new in dojo, and I have to enhance one of the forms: add an event handler to the dataGrid
so when the row of the grid is selected one of the buttons become enabled.
dataGrid
described in HTML as follows:
<div class="selectedGridContainer" data-dojo-attach-point="_selectedDataGridContainer">
<div class="selectedGrid" data-dojo-attach-point="_selectedDataGrid" ></div>
</div>
And the JS file that controls the form behavior mentioned this _selectedDataGrid
only once, in the postCreate
function:
postCreate: function() {
this.inherited(arguments);
this.textDir = has("text-direction");
this.hoverHelpList = [];
domClass.add(this._selectedDataGridContainer, "hasSorting");
this._renderSelectedGrid();
_renderSelectedGrid()
is being executed, which contains the only mention:
_renderSelectedGrid: function() {
.......
this._selectedDataGrid.appendChild(this._selectedGrid.domNode);
I've tried to add an data-dojo-attach-event onRowClick: enableRemoveUsersButton
in the HTML and a
enableRemoveUsersButton: function(evt){
this.removeUsersButton.set('disabled', true);
},
in js file. Didn't help.
Then I tried:
dojo.connect(myGrid, "onRowclick", function update() {
this.removeUsersButton.set('disabled', true); });
but I couldn't acquire myGrid
object using:
`var myGrid = dojo.byId("_selectedDataGrid");`
Can anyone tell me how to acquire the grid object and/or add an event handler to this grid, that fires when the row of the grid is selected?
Thank you!
回答1:
You won't be able to get the grid
object by dojo.byId("_selectedDataGrid")
. It is better to keep the myGrid
object at class level (widget level) and connect
using dojo.hitch
.
dojo.connect(this.myGrid, 'onRowClick', dojo.hitch(this, function(){
//access myGrid using this.myGrid and do the handling
}));
回答2:
From what you have share, I can see that the node "_selectedDataGrid" is just a Div tag. and your dataGrid widget may be "this._selectedGrid" so you should be add the event on that widget not the container node.
Also there is dijit.byId to get the instance of dijits/widgets. and dojo.byId is used to search of dom nodes.
Hope this was helpful.
来源:https://stackoverflow.com/questions/37181933/dojo-datagrid-event-attach-issue