Alpha Video Training
Results 1 to 7 of 7

Thread: Count children and show count on Parent list with a twist

  1. #1
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    338

    Default Count children and show count on Parent list with a twist

    I know how to show the count of child rows on each row of a parent list (with pre-fetched data for the lists destined to work while disconnected) with:

    on the onItemDraw event of the parent list, I have...
    Code:
    if (typeof data.__LIST__LIST_MYLIST != 'undefined')
    {
    	$('spanNumberOfItems'+index).innerHTML = data.__LIST__LIST_MYLIST.length;
    }else{
    	$('spanNumberOfItems'+index).innerHTML = 'There is no list data';
    }
    However, I don't just want to count the children, I would like to count the number of children where a field in the child list, myField, = 1. So basically I want to count a subset of the children belonging to each parent item.

    Any ideas?

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: Count children and show count on Parent list with a twist

    You have all the child data you need in the available data object.

    Using the Javascript .filter method, you can filter the data object for a specific property value...

    Code:
    var childLen = data.__LIST__LISTCHILD.length;
    var childData = data.__LIST__LISTCHILD;
    
    var objFilter = childData.filter(function( obj ) {
      return obj.myField == 1;
    });
    
    var cntFilter = objFilter.length;
    childLen is what you're already getting... the count of all children.
    childData is all the data for the child

    Now we filter and return an object of all child data rows based on your criteria.

    Then we get the length of the returned filtered data object.

    You could also just loop through the children...

    Code:
    var cntFilter = 0;
    for(i=0;i<childData.length;i++){
    	if(childData[i].myField == 1){
    		cntFilter += 1;
    	}
    }



    Nice question... thanks.
    Last edited by Davidk; 12-09-2016 at 11:29 PM.

  3. #3
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    338

    Default Re: Count children and show count on Parent list with a twist

    Thanks David. That worked great!
    I used it to visually show in the parent list that when childLen doesn't equal cntFilter that the user has some work left to do on that particular item.
    The user is no longer required to navigate down to the child list to see if there is some work to be carried out.

  4. #4
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    398

    Default Re: Count children and show count on Parent list with a twist

    This is the start of what I want to do. I want to do the same count on a field value but on a list with no child list. How would that be formatted?

  5. #5
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    338

    Default Re: Count children and show count on Parent list with a twist

    Quote Originally Posted by dfricke10 View Post
    This is the start of what I want to do. I want to do the same count on a field value but on a list with no child list. How would that be formatted?
    The original message was to get help on how to, for each row in the parent list, get the count for the child rows for each of those parent rows. And this specifically in the case where the child list row data is pre-loaded along with its parent's rows.

    As you don't have a child list, I understand what you want to be different but I'm not clear on what that might be.
    Do you want to, for each row of a first list, show a count of a field value of another list that isn't technically a child but is nevertheless linked by some key?

  6. #6
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    398

    Default Re: Count children and show count on Parent list with a twist

    Thanks, Jeff. What I want to do is just get a count of the number of rows in a list with a specific field value. I can get the count of all the rows, but need ONLY the rows with CATEGORY = 1.

    My original thread is here: https://forum.alphasoftware.com/show...l-Change-Price

    I figure if I can get started with the row count I can try to figure out the rest.

  7. #7
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    338

    Default Re: Count children and show count on Parent list with a twist

    Something like in the attached UX?
    (the only code I added was in the onListDraw list1 event)

    catCount.a5wcmp

    Although the code probably will not work with older browsers, you could run the code through Babel (https://babeljs.io) to get some code that would.

Similar Threads

  1. Replies: 5
    Last Post: 11-16-2016, 06:37 PM
  2. List control displaying children (parent/children scenario) does not load
    By WindForce in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 11-14-2016, 08:36 AM
  3. Show count of child records in List2 on List1's List Layout for each record
    By jgrannis in forum Mobile & Browser Applications
    Replies: 5
    Last Post: 07-12-2016, 11:15 PM
  4. Count Parent records in a Set
    By David Boomer in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 04-19-2010, 07:00 PM
  5. Licensed user count and network users count
    By Rokrz in forum Alpha Four Versions 7 and 8
    Replies: 0
    Last Post: 05-17-2007, 10:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •