Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Trying AJAX update of tables #19

Open
xDaizu opened this issue Jul 22, 2015 · 0 comments
Open

Trying AJAX update of tables #19

xDaizu opened this issue Jul 22, 2015 · 0 comments

Comments

@xDaizu
Copy link

xDaizu commented Jul 22, 2015

First of all, I like your plugin very much, it's easy and simple. I wanted to tweak it a little bit so it updates the server-side data through ajax on change.

For that I made my .on("change") return a deferred object and changed your code to expect that.

Changed from:

 if (evt.result === false) {
            active.html(originalContent);
           }

to:

jQuery.when(evt.result)
    .done(function (result) {
                if (result !== null && typeof result === 'object') {
                    //if it's an object
                    if (result.success) {
                        //if the property exist or has a truthy value
                        return true;
                    }
                } else {
                    //it's a value or null
                    if (result) {
                        //if it has a truthy value
                        return true;
                    }
                }
               //it has a falsey value
                active.html(originalContent);
            })
    .fail(function () {
                active.html(originalContent);
            });

The beauty of using ".when()" is that it keeps working if you return a not deferred object. For instance, false, so it doesn't break your current functionality, but I have a problem I don't know how to solve.

The originalContent attribute gets overwritten, so if I change a cell and quickly change another cell and both fail, the 2nd one will get the originalContent of the 1st one, and the 1st one will keep the new content.

Any idea about how to fix this? I think that if we manage to, this would be a great addition to your already excellent widget. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant