jQuery UI сортируемый, как проверить, последний ли tr и удалить класс - PullRequest
0 голосов
/ 13 июня 2011

У меня есть табличка с формой, в которой используется сортировка для перетаскивания, а также стрелки вверх и вниз, по которым можно перемещаться по строкам вверх и вниз.Когда таблица сформирована, я скрываю стрелку вверх в первой строке и стрелку вниз в последней.Но при перетаскивании или использовании стрелок для перемещения строк вверх и вниз он не обновляет стрелки вверх и вниз.Как мне решить это:

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.    
            } 
        });
    }

1 Ответ

1 голос
/ 13 июня 2011

Попробуйте следующий код, чтобы найти последний tr:

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

Надеюсь, это поможет ...

...