Skip to content

Commit

Permalink
feature: numeric cell type (solves #443, #397, #336, partially replac…
Browse files Browse the repository at this point in the history
…es pull request from #121)
  • Loading branch information
warpech committed Feb 26, 2013
1 parent e5af5d7 commit a052013
Show file tree
Hide file tree
Showing 20 changed files with 1,597 additions and 117 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## HEAD

Features:
- numeric cell type. Updated pages [Numeric](http://handsontable.com/demo/numeric.html) and [Column sorting](http://handsontable.com/demo/sorting.html). Solves issues [#443](https://github.com/warpech/jquery-handsontable/issues/443), [#397](https://github.com/warpech/jquery-handsontable/issues/397), [#336](https://github.com/warpech/jquery-handsontable/issues/336). Partially solves issue ([#121](https://github.com/warpech/jquery-handsontable/issues/121)

Bugfix:
- scrolls to top of table on any key press if the top is not on the screen ([#348](https://github.com/warpech/jquery-handsontable/issues/348))
- cell editor was using a wrong cell value if column order was manually changed ([#367](https://github.com/warpech/jquery-handsontable/issues/367))
Expand Down
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = function (grunt) {
'src/renderers/textRenderer.js',
'src/renderers/autocompleteRenderer.js',
'src/renderers/checkboxRenderer.js',
'src/renderers/numericRenderer.js',

'src/editors/textEditor.js',
'src/editors/autocompleteEditor.js',
Expand Down Expand Up @@ -64,6 +65,7 @@ module.exports = function (grunt) {
src: [
'jquery.handsontable.js',
'lib/bootstrap-typeahead.js',
'lib/numeral.js',
'lib/jQuery-contextMenu/jquery.contextMenu.js'
//'lib/jQuery-contextMenu/jquery.ui.position.js' //seems to have no effect when turned off on contextmenu.html
],
Expand Down
10 changes: 5 additions & 5 deletions demo/autocomplete.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8'>
<title>Autocomplete - Handsontable</title>
<title>Autocomplete cell type - Handsontable</title>

<!--
Loading Handsontable (full distribution that includes all dependencies apart from jQuery)
Expand All @@ -22,7 +22,7 @@
<!--
Facebook open graph. Don't copy this to your project :)
-->
<meta property="og:title" content="Autocomplete">
<meta property="og:title" content="Autocomplete cell type">
<meta property="og:description"
content="This example shows the usage of the Autocomplete feature.">
<meta property="og:url" content="http://handsontable.com/demo/autocomplete.html">
Expand Down Expand Up @@ -66,9 +66,9 @@ <h1><a href="../index.html">Handsontable</a></h1>
for HTML, JavaScript &amp; jQuery
</div>

<h2>Autocomplete</h2>
<h2>Autocomplete cell type</h2>

<p>This page shows how to use Handsontable with various data sources:</p>
<p>This page shows how to configure Handsontable with Autocomplete cell type:</p>

<ul>
<li><a href="#lazy">Autocomplete lazy mode</a></li>
Expand Down Expand Up @@ -132,7 +132,7 @@ <h2>Autocomplete lazy mode</h2>
source: ["BMW", "Chrysler", "Nissan", "Suzuki", "Toyota", "Volvo"],
strict: false
},
{},
{type: 'numeric'},
{
type: {renderer: myAutocompleteRenderer, editor: Handsontable.AutocompleteEditor},
source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"],
Expand Down
154 changes: 154 additions & 0 deletions demo/numeric.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Numeric cell type - Handsontable</title>

<!--
Loading Handsontable (full distribution that includes all dependencies apart from jQuery)
-->
<script src="../lib/jquery.min.js"></script>
<script src="../dist/jquery.handsontable.full.js"></script>
<script src="../lib/numeral.de-de.js"></script>
<link rel="stylesheet" media="screen" href="../dist/jquery.handsontable.full.css">

<!--
Loading demo dependencies. They are used here only to enhance the examples on this page
-->
<link rel="stylesheet" media="screen" href="css/samples.css">
<script src="js/samples.js"></script>
<script src="js/highlight/highlight.pack.js"></script>
<link rel="stylesheet" media="screen" href="js/highlight/styles/github.css">

<!--
Facebook open graph. Don't copy this to your project :)
-->
<meta property="og:title" content="Numeric cell type">
<meta property="og:description"
content="Numeric cell type uses Numeral.js as the formatting library.">
<meta property="og:url" content="http://handsontable.com/demo/numeric.html">
<meta property="og:image" content="http://handsontable.com/demo/image/og-image.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="409">
<meta property="og:image:height" content="164">
<link rel="canonical" href="http://handsontable.com/demo/numeric.html">

<!--
Google Analytics for GitHub Page. Don't copy this to your project :)
-->
<script src="js/ga.js"></script>

<script class="common">
function getCarData() {
return [
["Mercedes", "A 160", 2006, 6999.9999],
["Citroen", "C4 Coupe", 2008, 8330],
["Audi", "A4 Avant", 2011, 33900],
["Opel", "Astra", 2004, 7000],
["BMW", "320i Coupe", 2011, 30500]
];
}
</script>
</head>

<body>
<a href="http://github.com/warpech/jquery-handsontable">
<img style="position: absolute; top: 0; right: 0; border: 0;"
src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"/>
</a>

<div id="container">

<div class="rowLayout">
<div class="descLayout">
<div class="pad">
<h1><a href="../index.html">Handsontable</a></h1>

<div class="tagline">a minimalistic Excel-like <span class="nobreak">data grid</span> editor
for HTML, JavaScript &amp; jQuery
</div>
</div>
</div>
</div>

<div class="rowLayout">
<div class="descLayout">
<div class="pad bottomSpace150">
<a name="lazy"></a>

<h2>Numeric cell type</h2>

<p>By default, Handsontable treats all cell values as <code>string</code> type. This is because <code>&lt;textarea&gt;</code>
returns a string as its value.</p>

<p>In many cases you will prefer cell values to be treated as <code>number</code> type. This allows to format
numbers nicely and sort them correctly.</p>

<p>To trigger the Numeric cell type, use the option <code>type: 'numeric'</code> in <code>columns</code> array
or
<code>cells</code> function.</p>

<p>Numeric cell type uses <a href="http://numeraljs.com/">Numeral.js</a> as the formatting library. Head over to
their website to learn about the formatting syntax.</p>

<p>To use number formatting style valid for your language (i18n), load language definition to Numeral.js. See "Languages" section in <a href="http://numeraljs.com/">Numeral.js docs</a> for more info.</p>

<div id="example1"></div>

<p>
<button name="dump" data-dump="#example1" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
data to console
</button>
</p>
</div>
</div>

<div class="codeLayout">
<div class="pad">
<div class="jsFiddle">
<div class="jsFiddleLink">Edit in jsFiddle</div>
</div>

<script>
$("#example1").handsontable({
data: getCarData(),
startRows: 7,
startCols: 4,
colHeaders: ["Car", "Model", "Year", "Price"],
columnSorting: true,
columns: [
{
type: 'autocomplete',
source: ["Audi", "BMW", "Chrysler", "Citroen", "Mercedes", "Nissan", "Opel", "Suzuki", "Toyota", "Volvo"],
strict: false
},
{
//2nd cell is simple text, no special options here
},
{
type: 'numeric'
},
{
type: 'numeric',
format: '0,0.00 $',
language: 'de-de'
}
]
});
</script>
</div>
</div>
</div>

<div class="rowLayout">
<div class="descLayout">
<div class="pad"><p>For more examples, head back to the <a href="../index.html">main page</a>.</p>

<p class="small">Handsontable &copy; 2012 Marcin Warpechowski and contributors.<br> Code and documentation
licensed under the The MIT License.</p>
</div>
</div>
</div>
</div>
</body>
</html>
25 changes: 18 additions & 7 deletions demo/sorting.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,34 @@ <h2>Column sorting</h2>
colHeaders: true,
colWidths: [55, 80, 80, 80, 80, 80, 80],
columnSorting: true,
columns: [
{
type: 'numeric'
},
{},
{},
{},
{},
{},
{}
],
minSpareRows: 1
});
</script>
</div>
</div>
</div>
</div>
</div>

<div class="rowLayout">
<div class="descLayout">
<div class="pad"><p>For more examples, head back to the <a href="../index.html">main page</a>.</p>
<div class="rowLayout">
<div class="descLayout">
<div class="pad"><p>For more examples, head back to the <a href="../index.html">main page</a>.</p>

<p class="small">Handsontable &copy; 2012 Marcin Warpechowski and contributors.<br> Code and documentation
licensed under the The MIT License.</p>
</div>
<p class="small">Handsontable &copy; 2012 Marcin Warpechowski and contributors.<br> Code and documentation
licensed under the The MIT License.</p>
</div>
</div>
</div>
</div>
</body>
</html>
9 changes: 8 additions & 1 deletion dist/jquery.handsontable.full.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Tue Feb 26 2013 19:20:27 GMT+0100 (Central European Standard Time)
* Date: Tue Feb 26 2013 19:37:40 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down Expand Up @@ -224,6 +224,13 @@ AutocompleteRenderer down arrow
color: #777;
}

/*
NumericRenderer
*/
.handsontable .htNumeric {
text-align: right;
}

/* typeahead rules. Needed only if you are using the autocomplete feature */
.typeahead {
position: absolute;
Expand Down
Loading

0 comments on commit a052013

Please sign in to comment.