Is it possible to do paging (numbered) with firebase? - firebase

I started a project with firebase. Everything was perfect until it came to the paging section. But I was disappointed about paging. Please help me. Now I will write what I want to do.
There are 100 posts. I'll show 25 on each page.so this means 4 pages.When the user wants to move to the fourth page while on the first page, I want the data of the second and third pages not to be downloaded, only the data of the fourth page to be downloaded. one more example. when the user goes to "https://example.com/posts/page-3" I only want the posts on the third page to be fetched.
Is it possible to do this?

Your question does not specify if you are using Realtime Database or Firestore, but the answer is the same for both of them - it's not possible to do pagination using numeric offsets. In order to request a page of data that starts anywhere after the first item, you are required to know something about that item, or the one that comes right before it. If you don't know anything about that item, you have to start from the beginning, then work you way forward. That's how cursor-based pagination works.
With Firestore pagination, this why the API requires you to pass a DocumentSnapshot to start from, or field values from that document.

Related

How to track most used filters on product filter page with GTM and GA4?

I have a custom build page where users can filter products based on price, category, brand, ...
These are made out of checkboxes and a range input for the price.
I'm trying to figure out what the best way would be to track every action/filter in order to find out which brand / categories are the most popular.
Important to know
The menu contains a submenu for the categories. When the user clicks one of these links the filterpage will have this category checked in the filters.
The page does not reload when applying a filter. I'm using JS to perform a search and show new results. The page url gets updated with the correct search query parameters.
I think I have 2 options:
Track click events on the checkboxes and send every change with datalayer.push.
Track the page URL after each filter.
Option 1 is an issue because people might go to the page with some parameters in the URL. This won't be tracked because there was no click event. This issue will also apply to users that click the category in the submenu that prefills the filter.
Option 2 also is an issue because with this solution the category might be tracked 5 times if the user keeps adding or removing other filters. It always tracks all filters instead of the one that has been added.
The first step of tracking is using the analog of Occam's Razor. You want to cut off stuff that has no chance of answering legit business questions.
Your business question here is: What filters are the most helpful for the users? Now it's important to know why the business wants to know it. Cuz remember, the business is not very competent at data analysis even if it doesn't realize it.
So you need to know exactly how answering that question improves OKRs/KPIs. In this case, the legit answer could be: cuz we want to sort the filters by the usage frequency and measure if that would ease the engagement and thus, improve the conversion rate for the part of the journey from the product list to the pdp
That's a pretty weak reason, but passable. Especially if there's an issue in that transition currently.
Good, now having that context, why would we want to track filters used in pre-populated urls? Say some overzealous employee made a mistake and pre-populated some weird unneeded filter using, say, date and time of when the product has been added. And now they use that URL in all ads, so you get a lot of third party traffic coming to product lists with a date as a filter.
And then, let's say, that employee keeps using that filter for other persistent links to the effect of the date/time filter becoming uncanningly popular. There. Your data slowly becomes garbage and stops answering the original question.
There are other issues with tracking pre-set filters, some of which you've outlined, but the real issue is the ability of the data to answer good business questions clearly. Tracking all filters may be able to answer some technical questions, but it's not the aim of behavioral analytics to answer technical questions. Let them use access logs and whatever else they use to answer those.

How can I refresh an individual List Tile in a Listview.builder? Flutter

Situation:
I have an 'Event' item that you can click on --> Event detail screen.
That has individual subitems (date,participants,description) in the form of a list.
I load the subitems with a Future Builder into a Listview.builder with a List Tile like so:
I have a button to edit the location, it saves to the database and locally updates the location variable. This calls SetState().
The full list is updated, even if some tiles don't have changes.
THE PROBLEM
Some tiles, like the participants tile needs to load pictures and some other things that are time intensive. So even if I just change the location and update the list, everything reloads, consuming resources and taking too much time to load a simple string.
WHAT I AM LOOKING FOR
Is it possible to reload only a certain list tile? Would you use another widget instead of ListView.builder? Other logic? Any help is appreciated.
Answer Extension [Update]
The marked answer is correct. I was using future builder and that was forcing me to reload all data always. By using different Streams with Streambuilder I am able to change data on database and it automatically changes on the UI, without updating the state! Magic.
base on what i notices, Future Builder is the problem, Future builder rebuild the whole widget in the ListView.builder. in your case use StreamBuilder and you see the changes you what...

Fields depending on other fields issue

I am using Drupal 6.28 with Webform 6.x-3.18. I have a multi-step form setup. Some of my fields only show up if you select a radio button. In this particular instance this is a registration form and one of the questions is "Will you be bringing a guest?". If they select yes, then some additional fields drop down pertaining to their guest. So this works great. They can submit the form and everything works. The problem is, if they go back into their form to edit it and decide to go solo and now they are NOT bringing a guest, the guest fields disappear from the form as expected, but the data is still there behind the scenes and specifically in the database. So now when we go to run reports on some specific guest fields, those fields are throwing our reports off because the data is still there in the dB as if they are bringing a guest even though they are not now.
Can anyone think of the best place to handle this issue? Should I make a custom module that hooks into the webform somehow and catches for it and resets all the guest fields? I just don't know the best place to handle this.
THANKS
You could have some logic on the submission of the data. If it is the first time they are submitting (not already in DB), go forward as planned. If the data already exists, do a before and after compare on that field in question. If it toggled off you can clear your DB spots for that user.
You could also have something in the form code, so if that radio button is not checked, always insert some blank/null/however you handle it into the DB. This way, it is always writing in those fields as blank even if the data was there before (if you go ahead and rewrite that entire row in the DB anyway).

How to show a list over several pages

I am using Asp.NET MVC4 with Razor.
I want to show a list of items/entries (coming from a database) over several pages where the user can navigate to the next page or a specific page and each page shows e.g. 30 entries. It should be similar to the way the questions are structured in stackoverflow with this little page navigator at the bottom. How would I do that? I would guess that an example already exists but I have not found any.
Right now I show all my items on one page using a partial view in my index-view:
#foreach (var item in Model) {
#Html.Partial("_ItemInList",item)
I could probably only show the first 30 items but how do I store on which page I am and make the links so that the user can navigate to the other pages?
You could use a pagination control. There are many such components. For example you may take a look at MvcPaging hosted on GitHub.
There's an awful lot of ready made pagination controls available if you're looking for a quick result... but you're probably better off rolling your own. You can restrict your result set to a given page size in your data access layer using Linq and populate your model with single page (plus totals, page number etc...).
Depending on how you've structured your application though, you may want to push paging down to the database level and limit the result set size there rather than higher up the stack.

Architecture question involving search & session state

I have a grid with several thousand rows that can be filtered and sorted. On each row you can click a details button, which will bring you a new page with detailed information about the page. Because this is a button, you can't middle click or right click and open in a new tab. In addition, when clicking back you lose your filters and search results.
To solve this problem, I considered the following: Switch the buttons to links, and when filtering and searching, use get instead of post requests. This way, you could switch to new pages with a right click or middle click, and if you did follow a link normally, back would work properly.
This change was not made however. We were asked add a 'next result / previous result' set of buttons on the details page, that would allow you to navigate. While not an elegant solution, it would at least work.
I proposed adding querystring parameters to the details page, that would regenerate the search query based on filter, and allow you to get the next and previous results in code.
A team member took issue with this solution. He believes that it is a waste of server resources to re-query the database. Instead, a solution was proposed to add session variable that included a list of results. You could then use that to navigate.
I took issue with that because you can't have multiple tabs open without breaking navigation, and new results aren't appended to the list in real time. Also, if you worried about optimization, session would be the last thing to use since it eats memory and prevents server replication... unless you store the results back in the database.
What's the best solution?
Session doesn't sound like a winner, won't scale with lots of users.
Hitting the database repeatedly does seem unnecessary, but it depends on the cost - how many users, how often would they refresh/filter and what is the cost of that query?
If you do use querystrings you could cache the pages by parameter.
What about some AJAX code on that button to retrieve details - leave the underlying grid in place and display details in a div/panel or a new window/tab.

Resources