Live data from Hacker News

A spreadsheet in fewer than 30 lines of JavaScript, no library used

jsfiddle.net

261–270 of 274 posts

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#261
I am impressed with it. However the biggest complexity in a real spreadsheet is the implementation of a correct evaluation of the graph of dependencies. This evaluate sequentially and if you have a cell with a formula that use following cells, it is not going to work :-/

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#263
post #30

Are there any more full-featured libraries that people use for this? I've found SpreadJS[0], GelSheet[1], jQuery.Sheet[2], and ZK Spreadsheet, but none seem like thriving open-source projects as far as I can tell. [0] http://wijmo.com/demo/spreadjs/samples/index.html [1] http://www.gelsheet.org/demo [2] http://visop-dev.com/Project+jQuery.sheet [3] http://www.zkoss.org/product/zkspreadsheet

The most full featured OS JS spreadsheet I know of is ethercalc, check it out. It's even got a rest api..

Was going to comment along the same lines. Might not be "a library", but absolutely worth a look:

https://github.com/audreyt/ethercalc

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#264
I used fair amount of excel that is the reason why I am commenting. Just because you can enter some numbers in cell you cannot call it a spreadsheet. The main problem I see in your spreadsheet is the data entry. After you enter something you have to hit tab. no other key works. The main feature for any spreadsheet should be ease of data entry. Also other feature should be selecting the cell with mouse (instead of entering A1 I should be able to select A1)

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#265

Earlier quoted context omitted.

Sure, table layout is how you'd have to do this. To me this shows that half of HTML/CSS happened because of legacy issues and not with deliberate thought. The semantic web is mostly dead other than to help Google parse out their own ads while CSS remains a mess full of hacks like this.

There was never anything wrong with the table layout algorithm, what sucked was that there wasn't any way to apply it without typing your HTML rigidly to that structure. The situation still isn't perfect and flexbox is a strange alternative that I'm not quite happy with yet, but you can't deny that the HTML in my example represents the content you described with almost no extra layout fluff.

Fair enough. Perhaps this wasn't the best example.

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#266
post #191

Earlier quoted context omitted.

Eh, it's pretty easy to get things not on the far side of the screen; it's just hard to get it precisely in the center.

Center something vertically :). Or even better, create three divs, arranged horizontally, with a different amount of text such that all the divs are the same width and height. Note that you cannot specify a height for the parent since the text may be of arbitrary length. Makes me sad every time.

[deleted]

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#267
post #137

Earlier quoted context omitted.

A 30 line javascript spreadsheet is similar for me to when I first saw Norvig's 21 line python spelling corrector ( http://norvig.com/spell-correct.html ): this language is more powerful and expressive than I thought. I'm increasingly believing that HTML/CSS/JS in a browser is a viable common runtime. This demo does quite a lot to solidify that belief.

The only things that are powerful and expressive in JavaScript are bastardized beyond recognition versions of ideas from Lisp, Smalltalk and Self. You get those dynamic mechanisms that we know for 50 years now (lambda expressions and runtime method dispatch, oh wow) to be useful but without learning any lessons learned in those 50 years about how to design a coherent language based on those concepts, you just get a h…

What breaks my heart when someone claims that JavaScript was inspired by Self, is how Self was all about the wonders of multiple inheritance and dynamically mutable parent slots. JavaScript totally missed the boat on that one, with only one prototype slot, and the only time you can set it is when you create the object with "new".

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#268
post #137

Earlier quoted context omitted.

A 30 line javascript spreadsheet is similar for me to when I first saw Norvig's 21 line python spelling corrector ( http://norvig.com/spell-correct.html ): this language is more powerful and expressive than I thought. I'm increasingly believing that HTML/CSS/JS in a browser is a viable common runtime. This demo does quite a lot to solidify that belief.

The only things that are powerful and expressive in JavaScript are bastardized beyond recognition versions of ideas from Lisp, Smalltalk and Self. You get those dynamic mechanisms that we know for 50 years now (lambda expressions and runtime method dispatch, oh wow) to be useful but without learning any lessons learned in those 50 years about how to design a coherent language based on those concepts, you just get a h…

I recently found myself needing to use "with", and hating myself for it. Does anyone know a better way to do this in JavaScript?

    // Take an array of context dictionaries, and return a                                                                                      
    // function that evaluates a string in those contexts.                                                                                      
    // I fully realize how horrible this code is, and that                                                                                      
    // it only supports up to ten contexts. I feel terrible                                                                                     
    // about it, as I should, but I would feel even worse                                                                                       
    // if it were impossible to do this. But isn't there                                                                                        
    // a simpler way to do this is JavaScript? Maybe I                                                                                          
    // could use __proto__ inheritence, but I was hoping                                                                                        
    // to avoid.                                                                                                                                
    function evalInContextsFunction(_contexts) {
        var _contextCount = _contexts.length;
        if (_contextCount == 0) {
            return function evalInContexts(_text) {return eval(_text)};
        }
        with (_contexts[0] || {}) {
            if (_contextCount == 1) {
                return function evalInContexts(_text) {return eval(_text)};
            }
            with (_contexts[1] || {}) {
                if (_contextCount == 2) {
                    return function evalInContexts(_text) {return eval(_text)};
                }
[...and so on...]

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#269
post #94
post #30

Are there any more full-featured libraries that people use for this? I've found SpreadJS[0], GelSheet[1], jQuery.Sheet[2], and ZK Spreadsheet, but none seem like thriving open-source projects as far as I can tell. [0] http://wijmo.com/demo/spreadjs/samples/index.html [1] http://www.gelsheet.org/demo [2] http://visop-dev.com/Project+jQuery.sheet [3] http://www.zkoss.org/product/zkspreadsheet

I'd really love to see one that supports a hierarchy of JSON data, such as a treegrid.

how much money is that worth to you?
Post reply on HN