Hi Hackers,
In the attached patch, newly created columns in a table are sorted
according to their creation order rather than the alphanumerical order.
Previously this was not happening without context refresh.
Please review.
Thanks
Sathish V
diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js
index 9a2980a..2c50ab0 100644
--- a/web/pgadmin/browser/static/js/browser.js
+++ b/web/pgadmin/browser/static/js/browser.js
@@ -1001,12 +1001,12 @@ define('pgadmin.browser', [
while (e >= s) {
i = items.eq(s);
var d = ctx.t.itemData(i);
- if (
- pgAdmin.natural_sort(
- d._label, _data._label
- ) == 1
- )
- return true;
+ if(d._type==='column'){
+ if (pgAdmin.numeric_comparator(d._id, _data._id) == 1) return true;
+ }
+ else{
+ if (pgAdmin.natural_sort(d._label, _data._label) == 1) return true;
+ }
s++;
}
if (e != items.length - 1) {
@@ -1026,24 +1026,48 @@ define('pgadmin.browser', [
while (e - s > 22) {
i = items.eq(s);
d = ctx.t.itemData(i);
- if (
- pgAdmin.natural_sort(
- d._label, _data._label
- ) != -1
- )
- return true;
+ if(d._type==='column'){
+ if (
+ pgAdmin.numeric_comparator(
+ d._id, _data._id
+ ) != -1
+ )
+ return true;
+ }
+ else{
+ if (
+ pgAdmin.natural_sort(
+ d._label, _data._label
+ ) != -1
+ )
+ return true;
+ }
i = items.eq(e);
d = ctx.t.itemData(i);
- if (
- pgAdmin.natural_sort(
- d._label, _data._label
- ) != 1
- )
- return true;
+ if(d._type==='column'){
+ if (
+ pgAdmin.numeric_comparator(
+ d._id, _data._id
+ ) == -1)
+ return false;
+ }
+ else{
+ if (
+ pgAdmin.natural_sort(
+ d._label, _data._label
+ ) != 1)
+ return true;
+ }
m = s + Math.round((e - s) / 2);
i = items.eq(m);
d = ctx.t.itemData(i);
- res = pgAdmin.natural_sort(d._label, _data._label);
+ if(d._type==='column'){
+ res = pgAdmin.numeric_comparator(d._id, _data._id);
+ }
+ else{
+ res = pgAdmin.natural_sort(d._label, _data._label);
+ }
+
if (res == 0)
return true;
diff --git a/web/pgadmin/static/js/pgadmin.js b/web/pgadmin/static/js/pgadmin.js
index 68a86af..8f36410 100644
--- a/web/pgadmin/static/js/pgadmin.js
+++ b/web/pgadmin/static/js/pgadmin.js
@@ -115,6 +115,15 @@ define([], function() {
return 0;
};
+ pgAdmin.numeric_comparator = function(a,b) {
+ a= parseInt(a);
+ b= parseInt(b);
+ if (a < b)
+ return -1 ;
+ else
+ return 1 ;
+ };
+
/**
* Decimal adjustment of a number.
*