Thursday, September 29, 2011

jquery tablesorter.filter.js my adding code ( filter count sum )

1.filter үүсгэж байх үед бүх талбарыг автоматаар хамруулах

this.construct = function () {
      var settings = arguments; // Allow multiple config objects in constructor call
........................
      return this.each(function () {
                    //adding code
                    if (settings.filterColumns == null) {
                        settings.filterColumns = [];
                        var trs = $(this).find(">tbody>tr");
                        if ($(trs).size() > 0) {
                            var tr = $($(trs).get(0));
                            var l = $(tr).children().size() - 1;
                            for (var i = 0; i < l; i++) {
                                settings.filterColumns[i] = i;
                            }
                        }
                    }

                    //adding code end
.........................
       });//this.each end
........................
};//this.construct end


2. filter хийж байх үед тоолох

function doFilter(table) {
..................
// Clear the table
$.tablesorter.clearTableBody(table);
// Push all rows which matched the search string onto the table for display. var resultRowsCount = resultRows.length;
for (var i = 0; i < resultRowsCount; i++) {
        $(table.tBodies[0]).append(resultRows[i]);
}

//adding code
                var tdcount = $(table).find("tfoot tr:eq(0) td.count");
                if ($(tdcount).size() == 0) {
                    if ($(table).find("tfoot").size() == 0) {
                        $("<tfoot>").appendTo(table).append($("<tr>"));
                    }
                    tdcount = $("<td>").appendTo($(table).find("tfoot tr:eq(0)"));
                    $(tdcount).attr("class", "count");
                }
                $(tdcount).text("Count (Тоо):" + $(table.tBodies[0]).children().size());

//adding code end
..................
}

3. filter хийж байх үед сонгосон талбарын нийлбэр харах tablesorter.js дотор

/* sorting methods */
            function multisort(table, sortList, cache) {
                var trsum = $(table).find("tbody tr");
                var sum = 0;
                try {
                    var trsuml = $(trsum).size();
                    for (var trsumi = 0; trsumi < trsuml; trsumi++) {
                        var tr = $(trsum).get(trsumi);
                        var tdi = sortList[0][0];
                       
                        var td = $(tr).children().get(parseInt(tdi));                       
                        sum = sum + parseInt($(td).text());
                    }
                } catch (e) {
                } finally {
                    var tdsum = $(table).find("tfoot tr:eq(0) td.sum");
                    if ($(tdsum).size() == 0) {
                        if ($(table).find("tfoot").size() == 0) {
                            $("<tfoot>").appendTo(table).append($("<tr>"));
                        }
                        tdsum = $("<td>").appendTo($(table).find("tfoot tr:eq(0)"));
                        $(tdsum).attr("class", "sum");
                    }
                    $(tdsum).text("Sum (Нийлбэр): " + sum);
                }

........................

No comments: