user794846
user794846

Reputation: 1931

jQuery UI sortable, how to check if its the last tr and remove class

I have a tabel with a form in it that is using sortable to allow drag and drop sorting, it also has up and down arrows that can be clicked to move rows up and down. When the table is generated I hide the up arrow on the first row and the down arrow on the last. But when dragging and dropping or using the arrows to move rows up and down it does not update the up and down arrows. How do I solve this:

function sortt() {

    $("#table_or tbody tr:first").find(".moveUp").hide();
    $("#table_or tbody tr:last").find(".moveDown").hide();

    $("#table_or tbody tr").each(function(){              
        $idx = $("#table_or tbody tr").index(this)+1;
        $(this).find("input[name$=_order]").val($idx); 
        $(this).children("td").eq(2).html("Order: "+$idx);


        //updates zebra 
        $("#table_or tbody tr:odd").removeClass().addClass("zebra2");
        $("#table_or tbody tr:even").removeClass().addClass("zebra1"); 

       //Check if the custom input exists
        if($(this).find("input.custom_opt").val()!=undefined){    
            $val = $(this).find("input.custom_opt").val(); //get the value
            $val = $val.split("|"); //split the value string into an array
           // var cust_dis = $(this).find("input.cust_dis").val();
           // alert(cust_dis);
            $val[6] = $idx; //Update the order value within the array
            $newVal = "";
            //Loop through the array and recreate delimited string. 
            for( $i=0; $i<$val.length; $i++ ){
                if($i!=0){ $newVal = $newVal+"|"; }
                $newVal = $newVal+$val[$i];
                }
            $(this).find("input.custom_opt").val($newVal); //Give the custom input its updated value.    
            } 
        });
    }

Upvotes: 0

Views: 748

Answers (1)

Harun
Harun

Reputation: 5179

Try the following code to find the last tr:

      $('#myTableId tr:last').removeClass('className1 ClassName2');

Hope this helps...

Upvotes: 1

Related Questions