React-Redux Fetch data from api, search and lazy loading - reactjs

I have a list of data which are rendered by default (20 items) with lazy loading functionality (pagination) to load more data when the user scrolls to a certain position.
Now I need to implement a search functionality from the api itself, my question is:
Initially I have 20 items, when a user search they will get another 20 items based on the search term (the old set will be replaced), and when scrolling they will get page 2 from the list based on the search term.
So what is the best practice here to know when I need to concatenate the old data with the new batch or to replace the old set of data with a new one.
My question is more architectural, any help would be appreciated.

Because backend shall has paginator in search, you only would re render component with new information in such page(bit collection), in other words , if you has service backend pagination render "item component", if you search into a collection(javascript array) in browser , use "collection/list component" (map), you can use keys to property change

Related

How to store custom sort order in a web app

I am developing a React Firebase web app, and I want to implement a "custom" sort on top of sorting by name and date. How should I go about storing this "sort" information?
Do developers append a "key" property to the components themselves? How will reordering work then (do i shift every component's key values by 1? That seems inefficient). Or should I do a separate file or database entry that just stores the order as an array of component id keys?
Should all of this be resorted on page load or should I reorganize the data in a way where as soon as I request them they're already sorted?
I've tried adding the order key prop to every item but it seems overly complicated for a simple feature. I haven't had much luck searching this online.
Firestore allows you to orderBy and limit queries.
You can also specify a cursor to paginate more data on request.
See This Example in the docs for more info.

React router - different content if post in list vs own page

React router has very cool feature: if you have a list of items (Instagram for example) and if you click on one item, content opens in modal/overlay but if you copy-paste the link to new tab/window or share the link with a friend for example, it opens in its own page.
I would love to use this feature but I need to find a custom solution..
My posts are very data heavy
I've split posts data into 2 tables in database
1st is very lightweight containing essential data: 4-5 columns
2nd table is very heave, ~30 columns
When user uses search filter, list updates only with data from 1st table
If user clicks on post, it will open in a modal/overlay
I will recycle the data I already have (from 1st table) and also get rest of the data from 2nd table
However, when user shares the link or opens it in new tab/page, data from 1st table is not present. I would need to integrate a conditional logic:
If post opens in list view (modal/overlay), only get additinal 2nd table data
If it's opened in a new tab/window in its own page, get all the data, 1st table included
How could I integrate this with React router? Has anyone already tried it? This would also allow to use different layout/components when user opens item in page view. Is there a way to check it?
Or is there a flaw in my logic? I imagine list would update very fast because it doesn't require huge amount of data and also would modal/overlay because it recycles some of the data.
I read all the docs, also searched online - didn't find anything.
Modals in react router are great. I've used the pinterest example and adapted it to my own needs.
Ensure you do your check on state.modal===true in a master layout component to give you the modal styling.
you'll need to check if table 1 stuff is present in your state and dispatch an action to trigger the async call in componentDidMount. You should be fetching table 2 in all scenarios.

AngularJS dynamic table - RESTfull data

I have a big data portion that I would like to post in a table. However, the data should be sorted and paginated. I know I am able to pass the whole data to the client at once and then paginate it using angular, but this will be too slow. I prefer to pass the data page-by-page, so one the client want to open a page from a table to load the data for it.
Up until now I have created an API that returns me the data that I need, based on the page number and the number of rows on the page. However, I don't know how to use it with AngularJS.
Can you please help me?
It looks like a backend problem. If you are using a standard restful backend, use the limit/skip parameters, you can encapsulate into a paginate.
Example:
localhost:1337/dataTable?skip=0&limit=100
localhost:1337/dataTable?skip=100&limit=100
localhost:1337/dataTable?skip=200&limit=100
...
On the frontend use a table object like ng-Table, and use the pages to keep track of the offset, the page number and the total items available.
skip = (pagNum - 1 * pageSize)
limit = pageSize
Make your backend return you the page you want plus the available dataNumber so you can build the pages controller.
Documentation for skip/limit on sails
http://sailsjs.org/documentation/reference/waterline-orm/queries/limit
http://sailsjs.org/documentation/reference/waterline-orm/queries/skip
Best approach is to keep track of the limit and offset in your controller. Then when user selects new page (offset) or changes items per page (limit), update the corresponding values and use them to make a new http request.
You could call a function on ng-change of a dropdown and that drop down would contain values of page number and number of records to fetch. Or you can provide two text boxes one for page number other for number of records and keep a button and on its ng-click event that will take value of those text boxes and post to your server and bring back data based on new values in text boxes

To search a grid for a value in extjs

var record = store.findRecord('InterviewerID', id);
This line searches for the record visible on the grid.
If the record is present in the next page(Pagination) then it does not search.
Could you please provide a way to search the whole store?
The findBy approach still would not work.
Your store will only contain a single page of data returned from the server. To search across pages you would need to search server side and determine which page of data it exists on. Once you know which page of data the searched term exists on, you could load that page of data into your store.

Extract data from the dom into my model

I have a searchfield that when used shows multiple results (search for Star Wars and you get about 6 results in a list form). Every result has a "add movie" button which when clicked should save the data of that movie into my rails model.
I want to use Backbone to get a dynamic view for this process, so that when the movie is added it shows instantly without refreshing. The easiest way to do this would be to extract the data from the HTML (title, image-url) from the selected movie and store it into my model.
I've checked the Backbone model documentation, and I've already did the codeschool Backbone.js course, but still I find it hard to get started. Can someone point me in the right direction?

Resources