Skip to content

Commit

Permalink
sort table
Browse files Browse the repository at this point in the history
  • Loading branch information
evlach committed Aug 8, 2014
1 parent b4d4162 commit c15d348
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ Utils.urlParam=function (s){
};
Utils.UIRoleAdapt = function () {
var userRoles = accessdb.session.get("userRoles") || [];
$(".accessdbUserMessage").html("");
$(".accessdbUserMessage").remove();
if (accessdb.session.isUserCollaborator()) {
$(".roleExpertsOnly").show();
}
else {
$(".roleExpertsOnly").hide();
var msg = $('<p></p>').addClass("accessdbUserMessage").append("You need Collaborator Role for this action!");
var msg = $('<p role="alert"></p>').addClass("accessdbUserMessage").append("You need Collaborator Role for this action!");
$(".roleExpertsOnly").parent().append(msg);
}
if (accessdb.session.isUserAdmin()) {
$(".roleAdminOnly").show();
}
else {
$(".roleAdminOnly").hide();
var msg = $('<p></p>').addClass("accessdbUserMessage").append("You need Admin Role for this action!");
var msg = $('<p role="alert"></p>').addClass("accessdbUserMessage").append("You need Admin Role for this action!");
$(".roleAdminOnly").parent().append(msg);
}
if(accessdb.session.isLoggedIn()){
Expand Down Expand Up @@ -158,4 +158,61 @@ Utils.arrayToSqlVal = function (arr) {
val = val.substring(1, val.length - 1);
val = val.replace(/\"/g, '\'');
return val;
};
};

Utils.sortResultsTable = function (table) {
var cols1st = $(table).find("thead th");
var cols = [];
var first = null;
var count = 1;
$.each(cols1st, function (key, value) {
count++;
if (first != null) {
var col = {
key: $(value).text(),
cell: value,
cells: $(table).find("td:nth-child(" + count + ")").get()
};
// console.log(col );
cols.push(col);
}
else {
first = value;
}
});
cols = _.sortBy(cols, "key");
cols.unshift({
key: " ",
cell: first,
cells: $(table).find("th:nth-child(1)").get()}
);
$(table).empty();
var noRows = 0;
var currentRow = 0;
var noCols = cols.length;
var thead = $("<thead/>");
var trh = $("<tr/>");
for (i = 0; i < noCols; i++) {
var col = cols[i];
$(trh).append(col.cell);
noRows = col.cells.length;
}
$(thead).append(trh);
$(table).append(thead);
var tbody = $("<tbody/>");
for (k = 0; k < noRows; k++) {
var tr = $("<tr/>");
for (i = 0; i < noCols; i++) {
var col = cols[i];
cells = col.cells;
var cell = col.cells[k];
if($(cell).text().trim().length<1) {
$(cell).text("-");
}
$(tr).append(cell);
}
$(tbody).append(tr);
}
$(table).append(tbody);

}

0 comments on commit c15d348

Please sign in to comment.