I'm using a react component that need me to pass in below prop
<Pager
totalPages={10}
currentPage={1}
/>
I can't figure out the calculation as in the api I have total_items, not totalPages. if I have 50 total_items, how can I produce 5 for the totalPages prop? says my limit is 10.
Divide total_items by limit, and round the value up.
Math.ceil(total_items/limit);
50 items / 10 per page = 5 pages
55 items / 10 per page = 6 pages
you need to check if there is a quotient from the divide operation because there is apparently few items need to be showed in another page
for example:
6 items
5 limit
if we just divide and ceil we will get 1 which is incorrect because there is one item need an extra page to be counted
totalPages_pre = (total_items/limit)
totalPages = (search.total % page_size) == 0 ? totalPages_pre : totalPages_pre + 1
Related
I have found solution for pagination to take N elements per page
BUT the i don't found solution or documentation to get count number of pages.
is incorrect ,
PLS help
It is probable that your dataProvider.getList() doesn't return the correct total. The expected response format should be:
{ data: record[], total: number }
Where total is the total number excluding pagination (i.e. if you have a pagination of 10, but the query has 150 results, total should be 150 on every page).
See https://marmelab.com/react-admin/DataProviderWriting.html#example-rest-implementation for more information.
I'm working on a code that counts the meters some dogs have travelled. It's just a gif constantly in loop. Now I wanted to show an image every 50 meters for like 3 seconds.
That's how I have tried it:
if (i % Number.isInteger(50)) {
document.getElementById("orange").style.display = "block";
}
That's how I've tried it but it doesn't work.
Can someone help me with that?
Thanks!
You can use FLOOR:
let frames = Math.floor(i / 50)
That will be 0 until 1==50, then it'll be 1 until i==100.
So 1234 steps will give you 24 frames played.
Then you have to decide how many images you have, lets say 5 images:
let currentImageIndex = itterations % 5;
That'll make it it go 0,1,2,3,4,0,...
That means in our example: 24%5 = 4, display the 5th image (because 0 is the first, that makes 4 the fifth image).
document.getElementById("my-image").src = `frame${currentImageIndex}.png`;
If the person would take a few steps more, 1251 steps, divided by 50 = 25 frames, modulo 5 -> currentImageIndex==0.
Note: this is untested, but should give you something to build off of
Note: Your current solution isnt working because Number.isInteger(50) always returns true because 50 is an integer. It doesnt convert anything, it just tests of it is an integer.
I'm having a hard time finding a solution for a spreadsheet on google sheets, javascript language. I was seeing some things like group by and discard. But I still haven't been able to assemble anything mentally that would come to any result.
I need to find items and groups of items (summed) within a dataset that fits the given defined value.
I have a data sheet with defined values, here is an example list
item
value
1
100.00
2
53.50
3
45.00
4
67.00
5
32.50
6
35.60
7
34.70
I need groups of items to be formed so that their sum is ideally 100.00, but it can be something close to that, even a little higher would be possible, but the ideal would be up to (<=).
Expected result logic:
Group 1 = item 1 value 100.00
Group 2 = item 4 value 67.00 and item 5 value 32.50 (since the sum is
99.50, being the closest to 100)
Group 3 = item 2 value 53.50 and item 3 value 45.00 (since the sum is 98.50, being the closest to 100)
Group 4 = item 6 value 35.60 + item 7 value 34.70 (since the sum is 70.30)
It doesn't matter the order of the items or the formation of the item groups. Only items cannot be repeated.
As an output you would only need the items from each group. Ex:
1
4 5
2 3
6 7
But if it had all the results it would be excellent (group, items, total value)
Group 1 item(s) 1 total value 100.00
Group 2 item(s) 4 5 total value 99.50
Group 3 item(s) 2 3 total value 98.50
Group 4 item(s) 6 7 total value 70.30
I'm thinking this way, but I still haven't found how to do it
Action
Rule
Result
Check the maximum value of an ITEM as the LIMITER cannot be lower
Maximum value
Show maximum value. Ex: 100
Set LIMITER as long as it is equal to or less than an ITEM's maximum value
<=MaximumValue
Example: LIMITER: 100
Check if any ITEM has a value equal to the LIMITER 100
value == LIMIT
Set in sequential order (+1 in each cycle) the group number for items with a value of 100 first
check if any sum of ITEM is equal to LIMITER 100
sum of items = value of the limiter, without repeating items already listed
Set in sequential order (+1 in each cycle) the number of the group of items summed with a value of 100
check if any ITEM is = -0.01 which previous search
without repeating items already listed
Set in sequential order (+1 in each cycle) the number of the group of items with values lower than the limiter
check if any sum of items is = -0.01 which previous search
sum of items = value of fetched, without repeating items already listed
Set in sequential order (+1 in each cycle) the group number for summed items with values lower than the limiter
continue searches until no values remain
without repeating items already listed
Set list to last available item
Every help is welcome
I noticed this question is very similar to the knapsack problem. I'm not very good at explaining it, but here are some resources that do a far better job of explaining it than I could.
https://learnersbucket.com/examples/algorithms/knapsack-problem-in-javascript/
I just cannot figure this out, nor find any kind of similar question that makes any sense to me. My problem: I am extracting records from a database and displaying them in multiples of 12 per panel on my web page. I therefore need to know how many panels to display all records, using JavaScript (or possibly JQuery). Example:
records = 27;
panels = records / 12; //(which is 2.25)
Obviously I will need 3 panels to display all 27 records, but how can I get that from the result of 2.25? I've tried also using % instead of / but somehow I'm just not getting it.
records = 27; panels = Math.ceil(records / 12); // 3
Round up.
if result is not fully divisible by 12, then use Math.ceil (2.25) which equals 3
So, I have a list of items and I want to check how many pages I would need if I want to show , say, 10 items per page
ie
220 should give me 22 pages
134 should give me 14 pages
I am using the ceiling function to get the number of pages
var pages = parseInt(items)/10;
alert("pages " +pages);
alert(Math.ceil(pages));
The problem which I am having is if I have 7 items, I am expecting it to give me 1 page. However, I don't get any output.
I have noticed that I only get an output if the value for pages from
var pages = parseInt(items)/10;
is greater than 1 , How do I fix this problem?
I think your problem lies elsewhere. Consider the following Math.ceil operations:
> Math.ceil(220/10)
22
> Math.ceil(134/10)
14
> Math.ceil(7/10)
1
Then look at the operation that you might have handled -- a string version of a number:
> Math.ceil(parseInt("7")/10);
1
> Math.ceil(parseInt(" 7")/10);
1
> Math.ceil(parseInt(" 7 ")/10);
1
It would appear that Math.ceil is providing 1 as expected, unless your value of 7 is malformed.