Converted the PMA_sort_table into a jQuery function as there was a race condition caused due to simultaneous adding of a row and sorting of the table
This commit is contained in:
@@ -1828,44 +1828,46 @@ jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to sort a table's body after a new row has been appended to it.
|
* jQuery function to sort a table's body after a new row has been appended to it.
|
||||||
* Also fixes the even/odd classes of the table rows at the end.
|
* Also fixes the even/odd classes of the table rows at the end.
|
||||||
*
|
*
|
||||||
* @param jQuery obj table_body jQuery object that refers to the table's body
|
|
||||||
* @param string text_selector string to select the sortKey's text
|
* @param string text_selector string to select the sortKey's text
|
||||||
*/
|
*/
|
||||||
function PMA_sort_table(table_body, text_selector) {
|
jQuery.fn.PMA_sort_table = function(text_selector) {
|
||||||
//collect all rows
|
return this.each(function() {
|
||||||
var rows = $(table_body).find('tr').get();
|
var table_body = $(this);
|
||||||
|
//collect all rows
|
||||||
|
var rows = $(this).find('tr').get();
|
||||||
|
|
||||||
//get the text of the field that we will sort by
|
//get the text of the field that we will sort by
|
||||||
$.each(rows, function(index, row) {
|
$.each(rows, function(index, row) {
|
||||||
row.sortKey = $(row).find(text_selector).text().toLowerCase();
|
row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
|
||||||
|
})
|
||||||
|
|
||||||
|
//get the sorted order
|
||||||
|
rows.sort(function(a,b) {
|
||||||
|
if(a.sortKey < b.sortKey) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(a.sortKey > b.sortKey) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
|
||||||
|
//pull out each row from the table and then append it according to it's order'
|
||||||
|
$.each(rows, function(index, row) {
|
||||||
|
$(table_body).append(row);
|
||||||
|
row.sortKey = null;
|
||||||
|
})
|
||||||
|
|
||||||
|
//Re-check the classes of each row
|
||||||
|
$(this).find('tr:odd')
|
||||||
|
.removeClass('even').addClass('odd')
|
||||||
|
.end()
|
||||||
|
.find('tr:even')
|
||||||
|
.removeClass('odd').addClass('even');
|
||||||
})
|
})
|
||||||
|
|
||||||
//get the sorted order
|
|
||||||
rows.sort(function(a,b) {
|
|
||||||
if(a.sortKey < b.sortKey) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(a.sortKey > b.sortKey) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
})
|
|
||||||
|
|
||||||
//pull out each row from the table and then append it according to it's order'
|
|
||||||
$.each(rows, function(index, row) {
|
|
||||||
$(table_body).append(row);
|
|
||||||
row.sortKey = null;
|
|
||||||
})
|
|
||||||
|
|
||||||
//Re-check the classes of each row
|
|
||||||
$(table_body).find('tr:odd')
|
|
||||||
.removeClass('even').addClass('odd')
|
|
||||||
.end()
|
|
||||||
.find('tr:even')
|
|
||||||
.removeClass('odd').addClass('even');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1936,8 +1938,10 @@ $(document).ready(function() {
|
|||||||
.end()
|
.end()
|
||||||
.appendTo(tables_table);
|
.appendTo(tables_table);
|
||||||
|
|
||||||
|
$(tables_table).PMA_sort_table('th');
|
||||||
|
|
||||||
//sort the table
|
//sort the table
|
||||||
PMA_sort_table(tables_table, 'th');
|
//PMA_sort_table(tables_table, 'th');
|
||||||
|
|
||||||
//Refresh navigation frame
|
//Refresh navigation frame
|
||||||
window.parent.refreshNavigation();
|
window.parent.refreshNavigation();
|
||||||
@@ -2081,6 +2085,14 @@ $(document).ready(function() {
|
|||||||
$.post($(this).attr('action'), $(this).serialize(), function(data) {
|
$.post($(this).attr('action'), $(this).serialize(), function(data) {
|
||||||
if(data.success == true) {
|
if(data.success == true) {
|
||||||
PMA_ajaxShowMessage(data.message);
|
PMA_ajaxShowMessage(data.message);
|
||||||
|
|
||||||
|
//Append database's row to table
|
||||||
|
$("#tabledatabases")
|
||||||
|
.find('tbody')
|
||||||
|
.append(data.new_db_string)
|
||||||
|
.PMA_sort_table('.name');
|
||||||
|
|
||||||
|
//PMA_sort_table($("#tabledatabases tbody"), '.name');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PMA_ajaxShowMessage(data.error);
|
PMA_ajaxShowMessage(data.error);
|
||||||
|
@@ -127,7 +127,7 @@ function appendNewUser(new_user_string, new_user_initial, new_user_initial_strin
|
|||||||
.end();
|
.end();
|
||||||
|
|
||||||
//Let us sort the table alphabetically
|
//Let us sort the table alphabetically
|
||||||
PMA_sort_table($("#usersForm").find('tbody'), 'label');
|
$("#usersForm").find('tbody').PMA_sort_table('label');
|
||||||
|
|
||||||
$("#initials_table").find('td:contains('+new_user_initial+')')
|
$("#initials_table").find('td:contains('+new_user_initial+')')
|
||||||
.html(new_user_initial_string);
|
.html(new_user_initial_string);
|
||||||
|
Reference in New Issue
Block a user