Skip to content

UiTableEdit - save data

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.

{ 2 } Comments

  1. Massimiliano Balestrieri | 8 Maggio 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. Massimiliano Balestrieri | 9 Maggio 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)

Post a Comment

Your email is never published nor shared. Required fields are marked *