hack, jquery

UiTableEdit – save data

05.08.08 | 5 Comments

Ho provato un plugin ancora poco documentato ma che promette bene… anche perchè fa poco. quello che serve.

Ho appena scritto all’autore per capire se il mio “workaround” per salvare il dato modificato è inutile.
Non ho trovato metodi nativi per farlo.

Il plugin è reperibile qui:

http://gregweber.info/projects/uitableedit.html

Ho modificato giusto questo (riga 57).

Da

if( options.editDone ) options.editDone(val,orig_text, this)

A

if( options.editDone ) options.editDone(val,orig_text)

Per salvare la riga ho scritto questo:


jQuery(document).ready(function(){
    jQuery(".tablesorter").tablesorter();
    var t = jQuery('#tablesorter-demo');
    jQuery.uiTableEdit( t ,
        {
            editDone : function(val,orig_text,el){
                //console.log(val);
                //console.log(orig_text);
                //console.log(jQuery(el).parent().find(".key").text());
                var thead = jQuery("thead>tr>",t);
                //console.log(thead);
                var row = jQuery(el).parent().children();
                var data = [];

                //console.log(row);

                row.each(
                    function(nr){
                        var key = thead.eq(nr).text().replace(" ","_");
                        data.push(key + "=" + escape(jQuery(this).text()));
                    }
                );
                //console.log(data);
                jQuery.ajax({
                        type: "POST",
                        url: "./include/server.php",
                        data: data.join("&"),
                        success: function(msg){
                            console.log(msg);
                        }
                });

            }
        }
    ); // returns t

});
 

Ecco la Demo. Aprire con firebug attivo.

Popularity: 16% [?]

4 Comments

  1. Massimiliano Balestrieri
    Posted 8 May 2008 at 18:36 | Permalink

    Ecco la risposta di greg

    Sorry for my poor italiano …

    You should upgrade to the latest version- 0.4, as it fixes a potential focus blurring issue. It also allows use of the escape key.
    It also passes the parameter that you want

    if( options.editDone ) options.editDone(val,orig_text,e,td)

    There is nothing built in for saving server side- this is a very light-weight plugin. You may find my other plugin helpful for this task: http://plugins.jquery.com/project/tableLib
    When I want to save every table element, I will use $.ajax({ type: “POST”, …, data : { json : JSON.stringify( $(‘#my-table’).objects() ) } } );
    In the case of saving a row, you could use the plugin:
    $.row( row_selector ).to_object() -OR- $( row_selector ).row().to_object()
    For the json, I am using a standard JSON library

    Thanks for showing the demo- I have been meaning to put a demo up for a while. If you plan on maintaining it, I will link to it. I did notice a flaw in the demo (which may be the fault of my plugin). I am using Firefox 2, and after I am done editing a cell, the padding/margin is lost so the value moves to the upper left.

    Chao
    Greg Weber

  2. Posted 9 May 2008 at 09:00 | Permalink

    Ho corretto aggiornando l’ultima versione del plugin (0.4).

    La callback era stata corretta da Greg

    editDone : function(val,orig_text,ev, el)

  3. dailez
    Posted 25 August 2009 at 08:03 | Permalink

    Hello,

    I also have the problem with the padding/margin after I am done editing a cell.

    Has anyone found a workaround or a bugfix for that problem?

    Best regards
    dailez

  4. Posted 16 January 2010 at 10:40 | Permalink

    Hi folks,

    I really love this script. Had to rewrite the php part for saving from the scratch but it works really nice now.

    I succeeded in fixing the problem with the missing cell padding after editing a cell by adding “!important” to the td selector in the style.css. The code should look like this:

    table.tablesorter tbody td {
    color: #3D3D3D;
    padding: 4px !important;
    background-color: #FFF;
    vertical-align: top;
    }

One Trackback

  1. [...] serverseitig erfolgen. Es haben sich aber schon andere Leute damit auseinandergesetzt. Der Ansatz http://maxb.net/blog/2008/05/08/uitableedit-save-data/ hat mich inspiriert zu einer eigenen Lösung, die ich für ein Projekt [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*