How to count the number of rows in a jqGrid? - javascript

How do I count the number of rows in a jqGrid?
To clarify, there is not much data involved so the grid is pulling all of its data back from the server in a single query, instead of using pagination.

jQuery("#myGrid").jqGrid('getGridParam', 'records');
Update
Note there are two parameters to determine record count:
records
integer
Readonly property. Gives the number of records returned as a result of a query to the server.
reccount
integer
Readonly property. Determines the exact number of rows in the grid. Do not confuse this with records parameter. Although in many cases they may be equal, there are cases where they are not. For example, if you define rowNum to be 15, but the request to the server returns 20 records, the records parameter will be 20, but the reccount parameter will be 15 (the grid you will have 15 records and not 20).

$("#grid").getGridParam("reccount");
Readonly property. Returns integer. Determines the exact number of rows in the grid. (And not the number of records fetched).
More information here.

Here is the code I have so far. It seems like there should be a better way:
jQuery("#myGrid").getDataIDs().length;

How about this?
jQuery("#myGrid tr").length;
Actually, you can take that a step further with the optional context parameter.
jQuery("tr", "#myGrid").length;
Either one will search for every "tr" inside of "#myGrid". However, from my own testing, specifying the context parameter is usually faster.

jQuery("#myGrid").jqGrid('getGridParam', 'records');

You could try:
jQuery("#GridId").jqGrid('getDataIDs');

Related

How to apply limit on sequlize table rows number?

I want to apply limit on Sequelize table declaration.
This would actually limit the rows total of the table to 1 by forbidding to add more rows into it.
How can I achieve this in the table model definition?
I don't think that it is a good idea to use database table with only one row possible.
But a technical solution could be to use a default primary key (e.g. id: 1).
This primary key won't be auto increment or anything but a static default value like integer 1.
So that you could not add any other rows than the very first one, as a primary key is unique and it's value is always equals to 1. So you would only be able to update or read its value, if that's why you're trying to achieve.
But again this sounds like an anti-SQL thing to do.
You can use the 'limit' option in sequelize:
findAll({
limit: 2,
where: { YOUR QUERY }
)}
If you want to limit records, why don't do this in the controller / service / business logic part?
Before creating a record, you can findAll or count the records/rows what the current user have and apply your rule
Or even, you can add a beforeCreate hook if apply...

Dealing with null values in #DBLookup

I have a domino view with an amount column but some values are empty...and need to be. The problem is that the #Sum works fine until I have an empty value then it stops summing.
eg: if the values are 5,5,"" and 5 I get a sum of 10 and not 15.
I've traced the problem to the #DbLookup which is that it stops building the return array when it encounters a blank value. There is no built in method of dealing with null values.
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_atfunctions_dblookup_r.html
To make things harder, #dbLookup returns a string if only one is found or an array if more than one are found. If the values are 5,5,"" and 5 it returns an array of 2 values.
var alloc = #Sum(#DbLookup(#DbName(), "SubForms",MainFrmID , "ca_ca_ca_ca_amount"));
if (isNaN(alloc)){
return "$0.00";
}else{
return "$" + alloc.toFixed(2);
}
Can anyone help me refactor the #sum or #DbLookup to allow for empty values? Unfortunately I cannot define any new functions for this solution. The environment is locked down tightly. With a list of values of 5,5,"" and 5 I need a sum of 15.
I would try #Sum(#TextToNumber(#Trim(#Text(#DbLookup(...)))))
I would try
#Sum( #Transform( #Dblookup ( ....
If #DbLookup does not do what you need, you could always iterate over documents or view entries to build the sum.
The flow would be roughly like this:
1. Get a handle to the current database.
2. Get a handle to the "SubForms" view.
3a. Get a view entry collection using using getAllEntriesByKey() with MainFrmID as key, if a view column exists that displays the values you need.
--OR--
3b. Get a document collection using getAllDocumentsByKey() with MainFrmID as key, if no view column exists that displays the values you need.
4. Iterate over the collection to sum up values, using getColumnValues().get(columnNumber) to access the value from each view entry, or getItemValueDouble(fieldName) to access the value from each document.
That way you can easily detect null values and discard them.

Socrata, SODA, REST, JS: How to query number of rows?

I'm trying to figure out how to query a resource to see how many rows it has before I request the entire resource at once, or whether I use paging to bring back rows in batches.
For example, this resource here:
https://data.cityofnewyork.us/Transportation/Bicycle-Routes/7vsa-caz7
1) In cases where I know the number of rows, I can use the $limit parameter to ensure I get back everything. For example, this dataset has about 17,000 rows, so giving it a $limit of 20000 gets all of them.
For example:
https://data.cityofnewyork.us/resource/cc5c-sm6z.geojson?$limit=20000
also...
2) I thought maybe to make a metadata call, but while this request here returns metadata, number of rows is not part of it:
https://data.cityofnewyork.us/api/views/metadata/v1/cc5c-sm6z
However, I would like to know how many rows are in the dataset before I decide how to request them: all at once with the $limit parameter, or paging with the $limit and $offset parameters.
Ideas?
One method could be to count the rows using the COUNT function in the API call.
Should note that YMMV on this approach. Generally, the maximum is around 50,000 rows before you need to switch to paging. Generally, I'll always throw a 50k limit and have paging ready if it's larger.

Priority-Web-SDK: getRows has limit of 100 results

I am trying to get more than 101 rows from a Subform, for doing that, I am open the parent form and search for some value (by building a filter, using setSearchFilter and getRows(1)), right after I got the needed rows in the parent form, I opened SubForm (startSubForm), and with the instance of the subForms I called to getRows(1), getRows(1) return 101 results (rows) instead of 600 results.
How can I retrieve more than 101 results?
There is a limitation of retrieving up to 100 rows from priority when invoking getRows method. However, you can retrieve the rows in bulks by passing the fromRow param.
The definition of getRows according to the API is as followed:
getRows( fromRow, [onSuccess] , [onError] ) ⇒ Promise
When you invoke getRows(1) you will receive the first 100 rows.
You can get the second bulk by passing getRows(101) and so on.
A different option to get all the rows in one go is using REST API which has no limitation on the quantity of returned rows.

Firebase: best way to order and filter multiple childs

So as we know firebase won't let order by multiple childs. I'm looking for a solution to filter my data so at the end I will be able to limit it to 1 only. So if I won't to get the lowest price it will be something like that:
ref.orderByChild("price").limitToFirst(1).on...
The problem is that I also need to filter it by dates (timestamp)
so for that only I will do:
.orderByChild("timestamp").startAt(startValue).endAt(endValue).on...
So for now that's my query and then I'm running on all results and checking for that one row that has the lowest price. my Data is pretty big and contains around 100,000 rows. I can changed it however I want.
for the first query that gets the lowest price but all timestamps causes that the returned row might be the lowest price but not in my dates range. However this query takes ONLY 2 seconds compared to the second one which takes 20 including my code to get the lowest price.
So, what are your suggestions on how to do it best? I know I can make another index which contains the timestamp and the price but those are different data values and it makes it impossible.
full data structure:
country
store
item
price,
timestamp
just to make it even more clear, I have 2 inner loops which runs over all countries and then over all stores. so the real query is something like that:
ref.child(country[i]).child(store[j]).orderByChild("timestamp").startAt(startValue).endAt(endValue).on...
Thanks!

Categories