Last active
December 9, 2016 14:59
-
-
Save jtheisen/0268e6e6a9f291146ad0828eef80063d to your computer and use it in GitHub Desktop.
devextreme with mobx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Using DevExtreme with mobx outside React. --> | |
<div id="my-grid"></div> | |
<div id="my-button"></div> | |
<script> | |
var data = [ | |
{ | |
"ID": 1, | |
"CompanyName": "Super Mart of the West", | |
"City": "Bentonville", | |
"State": "Arkansas" | |
}, | |
{ | |
"ID": 2, | |
"CompanyName": "Electronics Depot", | |
"City": "Atlanta", | |
"State": "Georgia" | |
}, | |
{ | |
"ID": 3, | |
"CompanyName": "K&S Music", | |
"City": "Minneapolis", | |
"State": "Minnesota" | |
}, | |
{ | |
"ID": 4, | |
"CompanyName": "Tom's Club", | |
"City": "Issaquah", | |
"State": "Washington" | |
}, | |
{ | |
"ID": 5, | |
"CompanyName": "E-Mart", | |
"City": "Hoffman Estates", | |
"State": "Illinois" | |
} | |
]; | |
function bindDxWidget(widget, options) { | |
var observableOptions = observable(options); | |
observableOptions.onOptionChanged = function (e) { | |
console.info("option changed: " + e.fullName + " = " + e.value); | |
}; | |
mobx.autorun(function () { | |
for (var n in observableOptions) { | |
console.info('item ' + n + ' = ' + observableOptions[n]); | |
} | |
widget.option(observableOptions); | |
}); | |
return observableOptions; | |
} | |
var options = { | |
//dataSource: data, | |
//columns: [], | |
disabled: false, | |
searchPanel: { | |
visible: true, | |
text: "" | |
} | |
}; | |
var grid = $("#my-grid").dxDataGrid().dxDataGrid('instance'); | |
grid.option('dataSource', data); | |
options = bindDxWidget(grid, options); | |
$("#my-button").dxButton({ | |
text: "click", | |
onClick: function () { | |
var old = grid.option().searchPanel.visible; | |
//grid.option({ searchPanel: { visible: !old } }) | |
grid.option('searchPanel.visible', !old); | |
//options.searchPanel.visible = !options.searchPanel.visible; | |
//options.disabled = !options.disabled; | |
//console.info("obs now: " + obs()); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment