AutoDirector forum

The AutoDirector support and advice forum

Order by

Post Reply

Page: 1

Author Post
Member
Registered: Apr 2009
Posts: 10
Is there any way to add a field (downpayment) to the database and then add an option to the order by list to sort by this field?
Administrator
Registered: Apr 2008
Posts: 324
Currently, that would be a little difficult to achieve without some significant re-coding.

As a thought, you could put "Downpayment: XXXXX" as the first text in the more information field. It would then be possible to order the cars by that field in carlist.js.

Contact us with your full requirements for a quote if you would like us to handle the coding.
_______________
AutoDirector administrator
Member
Registered: Apr 2009
Posts: 10
What I did was I used the colour(color) field.

Is there anyway to have this field sorted numerically rather than as text?


Could changing the field type in the db accomplish this?

ex:

text sorting
1
10
2
21
3
31
etc...

numeric sorting
1
2
3
4
...
10
...
20



Thanks
Member
Registered: Apr 2009
Posts: 10
This seems to work for the sorting:


function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;var Char;

for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}

function numOrdA(a, b){ return (a-b); }
function numOrdD(a, b){ return (b-a); }

function SortCars(B,A,C)
{
var first = B;
var second = A;
var sortby = C;

if(IsNumeric(first) && IsNumeric(second))
{
if(sortby == 1)
{
return numOrdA(first, second);
}
else
{
return numOrdD(second, first);
}
}
else
{
if(B<A)
{
return (-1 * C);
}

if(B>A)
{
return (1 * C);
}
}

return 0;
}

Member
Registered: Apr 2009
Posts: 10
Hmm can't seem to edit my post...

Anyways small typo in my code:

Replace:
return numOrdD(second, first);


With:
return numOrdD(first, second);
Administrator
Registered: Apr 2008
Posts: 324
Thanks for the tip, agr.
_______________
AutoDirector administrator
Member
Registered: Apr 2009
Posts: 10
No problem.

Post Reply

Page: 1