<html data-ng-app="app">
<head>
<!-- ngHandsontable resources only included for demo purposes - it is NOT required by angular-simple-handsontable otherwise -->
<base href="http://handsontable.github.io/ngHandsontable/bower_components/">
<link rel="stylesheet" href="handsontable/dist/handsontable.full.css">
<script src="angular/angular.js"></script>
<script src="handsontable/dist/handsontable.full.js"></script>
<script src="https://rawgit.com/neam/angular-simple-handsontable/develop/angular-simple-handsontable.js"></script>
<script>
// To be able to use ngHandsontable's dataFactory in jsbin, a stub ngHandsontable module needs to be declared
angular.module('ngHandsontable', []);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<!-- demo helpers -->
<script src="../demo/js/services/dataFactory.js"></script>
<meta charset="utf-8">
</head>
<body data-ng-controller="MainCtrl as ctrl">
<h1>angular-simple-handsontable.js</h1>
<h2>Dynamic settings update</h2>
minSpareRows:
<input ng-model="ctrl.settings.minSpareRows">
rowHeaders:
true <input type="radio" ng-model="ctrl.settings.rowHeaders" ng-value="true">
false <input type="radio" ng-model="ctrl.settings.rowHeaders" ng-value="false">
<button ng-click="ctrl.addColumn()">Add column</button>
<button ng-click="ctrl.removeColumn()">Remove column</button>
<h2>Two-way deep data binding</h2>
<p>Changes shows up immediately only in tables that have deep watch active. Using deep watch is the default, but less performant on large datasets, so to turn off deep watch for larger datasets if you find your app sluggish. </p>
<input ng-model="ctrl.db.items[0].address">
<h2>Handsontable 1 (deep watch)</h2>
<simple-handsontable
settings="ctrl.settings"
data="ctrl.db.items">
</simple-handsontable>
<h2>Handsontable 2 (shallow watch)</h2>
<simple-handsontable
settings="ctrl.settings"
data="ctrl.db.items"
deep-watch="false">
</simple-handsontable>
<pre>
{{ ctrl.db.items | json }}
</pre>
<pre>
{{ ctrl.settings | json }}
</pre>
</body>
</html>
body {
margin: 2em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 1em;
color: #333333;
background-color: #ffffff;
}
a {
color: #0088cc;
text-decoration: none;
}
function MainCtrl(dataFactory, $timeout) {
var self = this;
this.minSpareRows = 1;
this.rowHeaders = false;
this.db = {items: dataFactory.generateArrayOfObjects()};
this.columns = [
{
data: 'id',
title: 'ID'
},
{
data: 'name.first',
title: 'First Name',
readOnly: true,
},
{
data: 'name.last',
title: 'Last Name',
readOnly: true,
},
{
data: 'address',
title: 'Address',
width: 150,
},
{
data: 'product.description',
title: 'Favorite food',
type: 'autocomplete'
},
{
data: 'price',
title: 'Price',
type: 'numeric',
width: 80,
format: '$ 0,0.00'
},
{
data: 'isActive',
title: 'Is active',
type: 'checkbox',
checkedTemplate: 'Yes',
uncheckedTemplate: 'No'
},
];
this.settings = {
colHeaders: true,
contextMenu: ['row_above', 'row_below', 'remove_row'],
minSpareRows: this.minSpareRows,
rowHeaders: this.rowHeaders,
columns: this.columns,
height: 300,
width: 700
};
this.addColumn = function() {
this.settings.columns.push({});
};
this.removeColumn = function() {
this.settings.columns.pop();
};
// For autocomplete
this.currentItemId = null;
this.settings.afterSelectionEnd = function(r,c,r2,c2){
// Keep track of the currently selected item's id
self.currentItemId = this.getDataAtCell(r,0);
};
this.columns[4].source = function (query, process) {
var currentItem = _.find(self.db.items, function(item) {
console.log('find', item.id, self.currentItemId);
return item.id === self.currentItemId;
});
var options = _.pluck(currentItem.product.options, 'description');
process(options);
};
}
MainCtrl.$inject = ['dataFactory', '$timeout'];
angular
.module('app', ['simpleHandsontable', /* ngHandsontable stub module only included for the dataFactory service: */ 'ngHandsontable'])
.controller('MainCtrl', MainCtrl);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |