Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2012, 05:23 AM   PM User | #1
oceanrace
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
oceanrace is an unknown quantity at this point
Question aspx feed to display business profiles by business type

Hello everyone,

My site displays business profiles from an aspx feed. The feed currently only lists profiles alphabetically.

I'm trying to display them within their category (Farms, Artists...).

This is the current alphabetical script running on the site:

<script type="text/javascript" src="http://www.managemymarket.com/js/jquery-1.3.2.min.js"></script>
<div id="dOX"></div>
<script type="text/javascript">
var arrVendors;
function ox(arr) {
arrVendors = arr;
var html = '';
for (var i = 0; i < arrVendors.length; i++) {
var v = arrVendors[i];
html += '<p><div class=\"vendor\"><a style=\"float:left\" href=\"\" index=\"' + i + '\">' + v.company + '</a><a style=\"float:right\" href=\"\" index=\"' + i + '\">+/-</a></div></p>';
html += '<div class=\"vendorinfo\" id=\"sub' + i + '\"></div>';
}
$('#dOX').html(html);
$('.vendor a').toggle(function(e) {
var idx = $(this).attr('index');
var vendor = arrVendors[idx];
var html = '<table><tr><td>';
html += '<b>' + vendor.company + '</b><br />' + vendor.city + ', ' + vendor.state + '<br />';
html += vendor.phone1;
if (vendor.website) html += '<br /><a target=\"_blank\" href=\"http://' + vendor.website + '\">' + vendor.website + '</a>';
html += '<br /><br />';
html += '<i>' + vendor.description + '</i></td>';
html += '<td>';
if (vendor.photo) {
html += '<img src=\"http://managemymarket.com/imgproxy.aspx?maxh=200&maxw=200&img=' + vendor.photo + '&hires=1\" />';
} else {
html += '';
}
html += '</td>';
html += '</tr>';
html += '</table>';
$('#sub' + idx).html(html).show();
}, function(e) {
var idx = $(this).attr('index');
$('#sub' + idx).hide();
});
}
</script>

<!--Here is the link for the JSON feed:-->
<script type="text/javascript" src="http://www.managemymarket.com/api/json.aspx?return=ox&method=vendors&orgID=149"></script>



The script below will categorize the businesses but only lists the business names (not profile details i.e. picture, products, website etc).

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<div id="dOX"></div>

<script type="text/javascript">
function fn1(vendors) {
var types = {};
for (var i=0;i<vendors.length;i++) {
var v = vendors[i];
if (!types.hasOwnProperty(v.type)) {
types[v.type] = new Array();
}
types[v.type].push(v);
}
var html = '';
for (var t in types) {
html += '<h3>' + t + ' (' + types[t].length + ')</h3><ul>';
for (var j=0;j<types[t].length;j++) {
var v = types[t][j];
html += '<li>' + v.company + '</li>';
}
html += '</ul>';
}
$('body').append(html);
}
</script>
</head>
<body>

</body>
<script type="text/javascript" src="http://www.managemymarket.com/api/json.aspx?orgid=149&return=fn1&method=vendors"></script>
</html>


Does anyone have any suggestions on how I could combine these two scripts to display the company profiles within their respective category?

Any help would be greatly appreciated!

Brian
oceanrace is offline   Reply With Quote
Old 12-09-2012, 09:13 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
The obvious answer is to change the ASP.NET code to allow you to specify a sort order. Much easier solution than mucking in the JS code.

All the ASP.NET code has to do is change the SQL query's ORDER BY clause to match your request.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 12-10-2012, 01:14 AM   PM User | #3
oceanrace
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
oceanrace is an unknown quantity at this point
Thanks Pedant,

I'm going back to the company that provides the feed and see if they are willing to change the SQL statement.

Thanks
Brian
oceanrace is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:11 AM.


Advertisement
Log in to turn off these ads.