flexgrid 精華(網上找不到這種案例了) 選中行 某列float資料求和 trSelected

ailinty發表於2014-02-02
技術交流群:179647190
下面有2個技巧,
1是得到所有選中行的id
2是得到所有選中行的某一列的所有資料求和。

function button(com, grid) {
  if (com == '加入) {
   if ($('.trSelected', grid).length == 0) {
    alert("請選擇至少一條資料");
   } else {
                var id = "";
                for ( var i = 0; i < $('.trSelected', grid).length; i++) {
                    if (i == $('.trSelected', grid).length - 1) {
                        id += "id="
                                + $('.trSelected', grid).find("td:first")
                                        .eq(i).text();
                    } else {
                        id += "id="
                                + $('.trSelected', grid).find("td:first")
                                        .eq(i).text() + "&";
                    }
                }
                var items = $('.trSelected',grid); //這個是關鍵
                var sum = 0;

              //累加選中所有行的第8列的資料,得到總和,
                items .each(function() {
                    sum += parseFloat($(this).children().eq(8).text());
                });

                var c  = document.getElementById("weifenpeimishu");
                 if(sum > c.value)
                 {
                     alert("超過總米數");
                 }
                else
                 {
                     var url = "xxxxxxxxaction&" + id;
                     add_ajax(url);
                 }
   }
  }

}

相關文章