Frage

I'm working on an xpages application in which I would like to display the top5 of the total volumes per client.

I have a list of customers who buy any number of products.I would like to classify customers according to the total volume of products purchased. I use the "Top5" View categorized by customer.

I used a document collection to calculate the total volume by customer.

I get to classify volumes in descending order and select the top 5.But this does not allow me to retrieve the name of the product and the client from the view.

var cls3 = @DbColumn("","Top5",1);
sessionScope.put("clientsList3",cls3);
var db=session.getCurrentDatabase();
var view7=db.getView("Top5")
var dataa =[] ;
         var top =[];

         for(var r = 0; r < clientsList3.length; r++){

           var Cli = @Trim(@Text(clientsList3[r]));
           var VolumeTotal :NotesDocumentCollection =  view7.getAllDocumentsByKey(Cli);

           var vola = 0;
           var array = new Array();
           var prod = "";

 if (VolumeTotal == 0) {array = 0;}
             else{
            var doca = VolumeTotal.getFirstDocument();
                while (doca != null)
                {vola = vola + doca.getItemValueInteger("TotalVolume_Intermediate");
                    doca = VolumeTotal.getNextDocument(doca);
                    }
                array.push(vola);

            }
        dataa[r] = array;
              dataa.sort(function(a, b) {return b - a;});         



   top = dataa.slice(0,5);


             } 

          return  dataa;

      }
War es hilfreich?

Lösung

You do want to use a managed bean for that, it makes a lot of things much easier. You create a custom class that does the compare operation for you:

   public Class TopSeller implements Comparable {
         String product;

      public String getProduct() {
        return this.product;
      }

      public void setProduct(String product) {
        this.product = product;
      }
        // Add properties as needed

      public int compareTo(Topseller theOther) {
           // Your ranking code goes here
      }
   }

In that class your compareTo function does provide the ranking and ordering. Then you just need:

  Set<TopSeller> allSeller = new TreeSet<TopSeller>();

... and you are done. The Treeset will provide the ready sorted result and you just bind it to a repeat with 5 rows to display

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top