Skip to main content

Hi


is there a method to count the total number of records returned when updating a smartview through a smartobject. I am returning many thousands of records but don't know how many exactly.  I would like to show this on screen


thanks

Hi


 


If you are using K2 Designer you can do the following:


Click on the view you want count > Select Edit > Click on any Column > Click on "Column Tab" in the Properties Menu > Click on the "Add" option located next to Count.


 


Kind Regards


Hi Psturmey


 


In regards to my last response, please confirm if this post has answered the question you had about counting the total number of records returned?


Hello,

 

 

I am facing same problem to count all list item.

I have almost 2000 row, and use paging to make it readable. when I use the Count agregation, it return only the count of displayed items instead of all data.

 

 

Is there any way to count all list?

or count list with specific value, for example I want to count the item that have price > 100? 

 

 

Thanks,

 

Hasyim


Hi, 

 

I am having the same questions, I don't want to add the view to count the items ... I just need to add how  many items where added in the sharepoint list where ParentId = XX

 

Any ideas?

 

Thanks in advance!


As for the counting items in a sharepoint list, I found this post that may be helpful in that regard:

 

http://community.k2.com/t5/K2-blackpearl/SmartObject-count-method/td-p/69122

 

The article it references has a somewhat clever way of counting items in a sharepoint list:

 

http://pawansatope.blogspot.com/2012/01/how-to-create-count-related-lookup.html


@ @Nur_Hasyim , I don't see a way to get a total count using the Count.  Did you ever get this to give you a total count?


Dear @ @Taffy_Lewis,

 

You can achieve this by creating stored procedure, check this out:

 

http://stackoverflow.com/questions/14474469/counting-the-number-of-rows-returned-by-stored-procedure


I'm running a very complicated (dynamic) stored procedure with double digits parameters.  The last thing I want to do (if I can avoid it) is run the procedure twice.  BTW, does K2 Smartobject support output parameters?

 

Well, using an OUTPUT parameter did not work!  So, I'm going to make two calls to get the record count, two calls?????


Hi Guys


 


The only out of the box method at this stage that I am aware of which can achieve a full count while pagination is enabled is to populate a hidden list control with the same data source as the list view and also a data label set to the value of 0, by adding them as a additional controls inside of the list view and then call the below rule construction when you need to (for example when button is clicked) to execute the below expression by calling it in the transfer date rule within a data label, this in essance will count all the records found in the dropdown list as the paginating limits the resources available to list view but not the dorpdown list therefore doing a full count.


 


Rule Construction


 When Button5 is Clicked



     for All items in Drop-Down List list control


          then transfer data (configure)


 


Expression:


DataLabel +1


 


Alternatively you are welcome to log this request as a feature request in our Ideas page page


 


Kind Regards


Raymond


This does not count the total rows.


Did you ever find a solution to this? The "stuff" below only return the number of rows on the current page not the total result set.


This method means that you need to load the list twice. Once to display the data and another time to count????? If the list view that is over 100+ rows would then load time is now doubled. There has to be a better method.

 

K2 will not accept any liability for any issues arising from actions taken in respect of the information provided by any forum member.


Hi Nguyenleely


 


Unfortuanitly there is no out of the box way to intercept the pagination exexution as it happen in line with the views initailization from the backend with no visibility to the user or view developer. The view will only count the amout of record is can find on the currently visible page when pagination is enabled on a list view.


 


There are however some alternative that can help get the total count onto the same view that is beign paginated however some of them could cause some loading delay, see the altenatives I could think of below:


 


Option 1


Obtain the total count with another smartobject call that would display the data eiter off-view in another view and pass the count to the current view.


 


Option 2


Obtain the total count with another smartobject call that would populate a sepearte control in the same view.  


Keep in mind that both option 1 and 2 would take additional load time which can cause loading delays on the view especially when there are thousands of records that need to load in.


 


Option 3 (best option in my opinion)


Another alternative which might be the best one to use to maintain performance and avoid double time on the view loading would be to do the count from the database side via an stored procedure and then create a smartobject from that stored procedure via the service instace used to connect to K2. You can then call the SmartObject on the list views initialize rule to populate a data label with the full count.I ran a quick test with this on a K2 5.2 installation and it seems to deliver the best  out of the box results preformance wise.


 


To see the results of the test and steps preformed, expand the following spoiler tag:


 


Step 1: Created a SmartObject and added 10 rows of data to it.
Step 2: Then enabled pagination on 5 rows per page.
16630iB2BF26F1CB90887B.png
Step 3: Created a the following stored procedure in SQL

Keep in mind that you would need to replace the "#####" section in the stored procedure with the name of the relevant table.


CREATE PROCEDURE ReturnCount 
AS
BEGIN
SELECT COUNT(*) FROM (K2].RSmartBoxData].B#####]
END
GO

--The below is used to execute the stored procedure
Execute ReturnNameCount;

Step 4: Created a SmartObject from the stored procedure via the SQL service instance
Step 5: Added a standard column count.
Step 6: Executed this SmartObject on the editable list views initalize method and returned the output to a data label called total count.
16634iB38807FDC7B44C5E.png

Referencing Community post:https://community.k2.com/t5/K2-Cloud/Total-Row-Count/m-p/108269#M112


 


Should you feel that this post is of use and or an accurate solution to the raised question, I kindly encourage you to mark it as such using the 'Mark as Solution', 'Kudo' andor ‘Me Too’ options.


 


Kind Regards


Raymond


 


Reply