-
Notifications
You must be signed in to change notification settings - Fork 664
Angular.js
You can use AlaSQL together with Angular.js framework. Please include the file normally and not via requireJS
$scope.exportData = function () {
alasql('SELECT * INTO XLSX("john.xlsx",{headers:true}) FROM ?',[$scope.items]);
};
See simple example in jsFiddle.
Another example: Calculating average of array
If AlaSQL recognize Angular.js it removes $$hashKey
artefacts from the exporting arrays.
To remove other artefact fields you can use [REMOVE COLUMNS](Remove Columns) clause.
(Source: AlaSQL Group by Built with AngularJS Application)
For example, you can integrate these libraries it for import or export data files from MS Excel.
HTML:
<button ng-if="$root.appInfo.model.rows" // show excel icon only if there are rows in the grid
class="btn"ng-click="$root.exportData()">
</button>
Controller:
$rootScope.exportData = function () {
alasql('SELECT * INTO XLSX("list.xlsx",{headers:true}) FROM ?',
[$rootScope.appInfo.model.rows]);
};
Unfortunately, we cannot use ng-change
because the input needs to be bound (ng-model
), but it seems that type=file
inputs are not supported for binding in Angular.js, so we can switch to ng-mouseleave
and it worked, though we had to check in the function that a file had been chosen.
HTML:
<input type="file" ng-mouseleave="loadFile($event)" />
Controller:
$rootScope.loadFile = function ($event) {
if (event.fromElement.files.length==0) {
return(false); // leave in case no file was chosen
};
alasql('SELECT * FROM FILE(?,{headers:true})', [event], function (data) {
$rootScope.eData = data; // eData contains the JSON representation of the Excel sheet rows
});
};
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo