mainrotor
asked on
I need help grouping an Array in my JavaScript code
Hi Experts,
I am working on a MVC.Net application with C#.Net code-behind.
I am using an Array in one of my views.
I am able to populate my array just fine, but I need to do the following once I have populated my array:
1. Group by the following fields: order, item, description
2. Sort by the following fields: order, item, description
I have included my javascript code below.
Please show me how to do my grouping and sorting of my javascript array.
Thank you in advance,
mrotor
I am working on a MVC.Net application with C#.Net code-behind.
I am using an Array in one of my views.
I am able to populate my array just fine, but I need to do the following once I have populated my array:
1. Group by the following fields: order, item, description
2. Sort by the following fields: order, item, description
I have included my javascript code below.
Please show me how to do my grouping and sorting of my javascript array.
var claimsHeader = new Array();
function onDataBoundHeader(arg) {
var dataItemsHeader = arg.sender.dataSource.view();
for (var j = 0; j < dataItemsHeader.length; j++) {
var order = dataItemsHeader[j].get("Item");
var item = dataItemsHeader[j].get("Market");
var description = dataItemsHeader[j].get("Description");
var claims = new Array(order, item, description);
claimsHeader.push(claims);
}
}
Thank you in advance,
mrotor
ASKER
The array I create, is generated from a grid. The data that loads into my array is sometimes repeated.
For example:
ORDER ITEM DESCRIPTION
ABC SHIRT SILK SHIRT
ABC SHIRT SILK SHIRT
DEF PANTS POLYESTER PANTS
I want the array to group by ORDER, ITEM, and DESCRIPTION so that the results are grouped as follows:
ABC SHIRT SILK SHIRT
DEF PANTS POLYESTER PANTS
How can I do this?
For example:
ORDER ITEM DESCRIPTION
ABC SHIRT SILK SHIRT
ABC SHIRT SILK SHIRT
DEF PANTS POLYESTER PANTS
I want the array to group by ORDER, ITEM, and DESCRIPTION so that the results are grouped as follows:
ABC SHIRT SILK SHIRT
DEF PANTS POLYESTER PANTS
How can I do this?
Do you mean you want to an array unique 'records' and then sort?
ASKER
Yes, Norie. I want an array's unique records and then sort.
Thank you for helping me clarify what it is I need. :-)
How can I accomplish this?
Thank you for helping me clarify what it is I need. :-)
How can I accomplish this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Julian,
I will try your suggestion and report my results.
mrotor
I will try your suggestion and report my results.
mrotor
ASKER
Thanks Julian.
Your suggestion worked.
Your suggestion worked.
You are welcome.
For sorting just use the Array.sort method.
Open in new window