Alpha Video Training
Results 1 to 24 of 24

Thread: Get Record Count of List using javascript

  1. #1
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Get Record Count of List using javascript

    I am trying to get the record count in a List Control using javascript before opening a report. This is because I want to prevent opening a report if there are over a certain number of records. I have tried the following 3 things and none of them work...

    Code:
    //the following one is from copying the one supplied by the defined Control to get record count 
    var countRec = {dialog.componentname}.list1.RECORDCOUNT;
    
    //I made the following one up
    var count = {dialog.Object}._getListRecordCount('LIST1');
    
    //I tried the following based on a thread in the forum
    var myOb = {dialog.Object}.getControl('LIST1');
    var countRec = myOb._data.length;
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  2. #2
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    In case someone is curious, here is the whole thing I am trying to run...

    Code:
    //the following one is from copying the one supplied by the defined Control to get record count 
    var countRec = {dialog.componentname}.list1.RECORDCOUNT;
    
    //I made the following one up
    var count = {dialog.Object}._getListRecordCount('LIST1');
    
    //I tried the following based on a thread in the forum
    var myOb = {dialog.Object}.getControl('LIST1');
    var countRec = myOb._data.length;
    
    if(countRec > 5000){
    	alert('The report would have '+countRec+' records based on your search.  To prevent server overload, reports cannot be opened if they have more than 5000 records.  Please narrow down your search.');  
    } else {
    	if(countRec > 1000){
    		var answer = confirm('The report requested has over 1000 records and will take several moments to open.  Is it OK to continue?');
    		if(answer == true) {
    			{grid.object}.runAction('ReportPayrollLedgerByEmp');
    		} else {
    			alert('The action to open the report has been cancelled.');
    		}
    	} else {
    		{grid.object}.runAction('ReportPayrollLedgerByEmp');
    	}
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

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

    Default Re: Get Record Count of List using javascript

    I can never remember if there is a method to get a list count... however, here are a couple of ways to do this...

    Your code does work...

    Code:
    var myOb = {dialog.Object}.getControl('LIST1');
    var countRec = myOb._data.length;

    Outside the List control...

    Code:
    var x = {dialog.Object}._listViewData.LIST1.length;
    where LIST1 (I believe in caps) is the name of your list control.

    And inside the List, in the onListDraw event you could save the count into a {dialog} namespace variable, and then use it elsewhere.

    Code:
    {dialog.Object}._myListCount = data.length;

  4. #4
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    Thanks, David, but I just tried the code below when 25,000 records were in the list control, and it ignored the count and just ran my action to open the report. This is being called by a button outside of the list control:

    Code:
    var countRec = {dialog.Object}._listViewData.LIST1.length;
    
    if(countRec > 5000){
    	alert('The report would have '+countRec+' records based on your search.  To prevent server overload, reports cannot be opened if they have more than 5000 records.  Please narrow down your search.');  
    } else {
    	if(countRec > 1000){
    		var answer = confirm('The report requested has over 1000 records and will take several moments to open.  Is it OK to continue?');
    		if(answer == true) {
    			{grid.object}.runAction('ReportPayrollLedgerByEmp');
    		} else {
    			alert('The action to open the report has been cancelled.');
    		}
    	} else {
    		{grid.object}.runAction('ReportPayrollLedgerByEmp');
    	}
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

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

    Default Re: Get Record Count of List using javascript

    First of all... yikes... 25,000 in the List control. How long does that take to load?

    Anyway... I just tried this with your code... and if countRec is set below the threshold being tested, then the logic is ok. Do you have your List control set to Page data? Do you actually have 25,000 records loaded?

  6. #6
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    The list control is paginated to 50 records at a time, but the deffined control for record count shows the total of records in the query, the 25,000. I need to get the total count of the records because the report is based on CurrentListFilter and I don't want it to have too many records .... So that code I used is just returning the total of the paginated records?
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

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

    Default Re: Get Record Count of List using javascript

    The List control, when "pageinated" holds that number of records... there are no more records in the list. You say you have a defined control that displays the total count... grab that.

  8. #8
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    I tried, see my first post.. It didn't work. It's the code Aloha gives you in their defined controls list for record count
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

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

    Default Re: Get Record Count of List using javascript

    Sorry... can't resist... is Aloha the Hawaiian office of Alpha?

    var countRec = parseInt($('{dialog.componentname}.LIST1.RECORDCOUNT').innerHTML);

    The Defined Control, List-Record count, is a static text control, with data being rendered inside a <span> tag. So you need to get the innerHTML of the tag... where the value it. Then use parseInt to convert it to an integer.

  10. #10
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    David, thanks so much for your time. I tried, but when the defined control shows 23,182 records, your code returns 23
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  11. #11
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    Well, now for some reason it is returning NaN
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  12. #12
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,298

    Default Re: Get Record Count of List using javascript

    To get the number of rows in the List's Query (as opposed to the number of rows of data that the list is currently displaying) you can do this

    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._state.recordCount;
    alert(count);

    obviously, if the list is not paginated then the number of rows shown in the list is the same as the number of rows in the list query (assuming that no client-side filter has been applied).

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

    Default Re: Get Record Count of List using javascript

    And to use your static text control...

    var countRec = $('{dialog.componentname}.LIST1.RECORDCOUNT').innerHTML;
    countRec = countRec.replace(/,/g,"")
    countRec = parseInt(countRec);

  14. #14
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    Thank you, thank you, thank you, Selwyn. That worked. My list is paginated to 50 and the count showed the total of around 25000, AND I used a filter list control to do some searching and it also returned the right count. YAY!!! I'm sure that will help others that are trying to get that list record count into their inline javascript.
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  15. #15
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    David, thanks to you too!
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  16. #16
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,460

    Default Re: Get Record Count of List using javascript

    Is there a way to get the count of the number of records in a list AFTER it has been filtered?
    Thanks,
    Jay
    Jay Talbott
    Lexington, KY


  17. #17
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    Have you tried using the List-Record Count that is under Defined Controls on a ux component?
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  18. #18
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,527

    Default Re: Get Record Count of List using javascript

    I also use Selwyn's suggestion in this thread to get the count in order to use it in my code.
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  19. #19
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,298

    Default Re: Get Record Count of List using javascript

    are you talking about a server-side filter or a client-side filter?

    if you are using a server-side filter then my post from 12/18/2014 applies

    Code:
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._state.recordCount;
    alert(count);
    if you are using a client-side filter then you can read the length of the _rData array property of the list. the _rData is the filtered data in the list

    Code:
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._rData.length;
    alert(count);
    Last edited by Selwyn Rabins; 03-05-2015 at 11:58 AM.

  20. #20
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,460

    Default Re: Get Record Count of List using javascript

    Thanks, Selwyn and Carol. Answered in less than 15 minutes. Where else can one get that type of support?
    Selwyn, the client side is what I am interested in.
    Thanks again.
    Jay
    Jay Talbott
    Lexington, KY


  21. #21
    "Certified" Alphaholic
    Real Name
    Jetson Lilibeth
    Join Date
    Dec 2011
    Posts
    1,093

    Default Re: Get Record Count of List using javascript

    This is the code of Selwyn
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._state.recordCount;
    alert(count);

    How do I count the number of rows in a not yet synchronized data? The above code returns zero , when I tried to save and synchronize the data on a list control and then run the code above in a button the alert says 'undefined'.

  22. #22
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,298

    Default Re: Get Record Count of List using javascript

    Quote Originally Posted by JetLi View Post
    This is the code of Selwyn
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._state.recordCount;
    alert(count);

    How do I count the number of rows in a not yet synchronized data? The above code returns zero , when I tried to save and synchronize the data on a list control and then run the code above in a button the alert says 'undefined'.

    The code you are using is appropriate when you have applied a server-side query to List. Say for example you have a list that is based on a sql table. Say also that the list is paginated and you are displaying 10 rows of data per page. The query that the list is based on might have a large number of rows, but the List always only shows 10 record (unless you are on the Last 'page' of data - in which case the List might show less than 10 rows). But you want to know how many records are in the List query, not how many records the List is currently showing (which is 10). In this scenario, list._state.recordCount would give you the answer you want.

    But your scenario is completely different. You want to know how many rows are in the list. The list data is in an array called _data. So you just need to return the length of this array. For example:

    Code:
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._data.length;
    alert(count);

    In addition, the List documentation documents a method to get the number of unsynchronized updated, edits and deletes.

    http://downloads.alphasoftware.com/A...DetailView.htm


    {dialog.object}.countRecordsToSynch(listId)

  23. #23
    "Certified" Alphaholic
    Real Name
    Jetson Lilibeth
    Join Date
    Dec 2011
    Posts
    1,093

    Default Re: Get Record Count of List using javascript

    Quote Originally Posted by Selwyn Rabins View Post
    The code you are using is appropriate when you have applied a server-side query to List. Say for example you have a list that is based on a sql table. Say also that the list is paginated and you are displaying 10 rows of data per page. The query that the list is based on might have a large number of rows, but the List always only shows 10 record (unless you are on the Last 'page' of data - in which case the List might show less than 10 rows). But you want to know how many records are in the List query, not how many records the List is currently showing (which is 10). In this scenario, list._state.recordCount would give you the answer you want.

    But your scenario is completely different. You want to know how many rows are in the list. The list data is in an array called _data. So you just need to return the length of this array. For example:

    Code:
    var lObj = {dialog.object}.getControl('ID_of_your_list');
    var count = lObj._data.length;
    alert(count);

    In addition, the List documentation documents a method to get the number of unsynchronized updated, edits and deletes.

    http://downloads.alphasoftware.com/A...DetailView.htm


    {dialog.object}.countRecordsToSynch(listId)
    Thanks so much! Hope you can point me in the right direction to enable lookup items availability when offline on a list control. the data are available but the problem is that lookup list are not available when offline.what could be the right property setting that I missed here?

  24. #24
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,298

    Default Re: Get Record Count of List using javascript

    Quote Originally Posted by JetLi View Post
    Thanks so much! Hope you can point me in the right direction to enable lookup items availability when offline on a list control. the data are available but the problem is that lookup list are not available when offline.what could be the right property setting that I missed here?
    unfortunately, i don't understand the question.

Similar Threads

  1. List Control VISIBLE count? Used when a list has some rows hidden.
    By CarlMPearson in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 10-21-2014, 09:56 PM
  2. how to calculate the row count (No of rows) in list.
    By PaulAmmoun in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 07-29-2014, 04:15 PM
  3. Row count of grid in javascript
    By frankbicknell in forum Application Server Version 11 - Web/Browser Applications
    Replies: 13
    Last Post: 11-27-2012, 08:13 AM
  4. record counting -- not count last record
    By dik_coleman in forum Alpha Five Version 6
    Replies: 6
    Last Post: 01-17-2006, 01:06 AM
  5. record count - delete button adjusting count
    By dik_coleman in forum Alpha Five Version 7
    Replies: 3
    Last Post: 12-23-2005, 12:06 PM

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
  •