Can React table render rows differently? - javascript

I have a table implemented in material table and it has served its purpose, unfortunately due to the poor performance issue where it re-renders every time there is a change in the state regardless of the states connection to the table itself.
I've opted to move to a different table and looking at React table as a possibility.
Can react table rows be customized that's not inline with the column data fully like the table below?
The parent has a different data compared to the sub-parent and the data in the sub-parent is different from its own parent (Which is the sub-parent).

To answer my own question.
Yes, react-table can certainly do these, you just need to conditionally render each row and table differently.

Related

onClick update the rows in table like structure REact JS and JSX

I am developing a react JS component with JSX coding structure that gets a JSON array of data from api. The component is a table like structure and has two arrows at the top and bottom. I want to achieve a functionality where on click of top arrow the table rows should be updated with new set of data in rows and vice-versa happens on click of down arrow. Is there a way to achieve this functionality?
It seems you are trying to do some sort of table paging. You can do this by storing the current page on the state of your control, and on the onClick handler:
make the call to the server API to retrieve the data for the next/previous page if you are paging and sorting on the server, then update the state with the retrieved data
or calculate and update the state with whichever rows you want to display if you already have all rows in memory but are showing a small set of them

React redux best practice for table row action

I have a list of items.
I render a Table component with this list.
I want to add a checkbox for each row.
Do I have to use a separate component for the table row iteself in order to set the current row style by checking it without rendering the whole table?
Becasase now when I change the item's 'selected' property, the whole table is rendering.
Thanks :)
If your whole table re-render, you should clearly update your code to avoid that. Like you said, you can have a component for each row, so when a row update, only the row re-render. I'm strongly suggesting you to do this. Be sure to include a key prop to each row to avoid performance leak. You can also use the shouldComponentUpdate method to avoid useless re-render. When passing your props down from the table component to the row component, make sure the objects your are passing are unique on don't change too often. If after all this, you realised you row will update and re-render often, you can try using react-virtualized, this library renders only the rows that are visible on the screen. If you need more help, you can also share some code.

get data from main grid to populate subgrid

I need to populate my subgrid which shows some of the columns from main grid without actually going and getting data again using URL? Example:Main Grid is getting data from server (10 columns) using jsonReader. Out of which I want to show 7 columns in the parent row and 3 columns in the subgrid row . Can I do this? (Or some other way to achieve this expand concept?)
One possible workaround to use the sub-grid as 1-1 with main grid, instead of as parent-child : query all the columns as normal in the parent grid, but set the ones you don't want in main row as hidden. Then in sub-grid load event, access those fields using the "parent" row id and create them as custom fields or simply emit custom html.
This does cause duplication of the fields though, since the original main grid fields are still present, even if hidden. The html ids will get duplicated and may cause conflicts if you don't handle them.
Perhaps there is a cleaner way to do it than this (which I'm sure #Oleg will show us any minute now!)
But I wish jqgrid had a documented feature to more easily handle this kind of thing. It is very useful because you get the benefit of full inline editing in the subgrid, so you can design a much nicer edit form (eg. multiline textareas) than when confined to one straight line.
Note the presence of this feature in other grids.
Jquery EasyUI Datagrid demo
Telerik Grid Editing Demo

ExtJS Grid storing Cell State automagically

I am porting quite a huge piece of software to an ExtJS Grid. Lots of data (and I mean lots of data) is loaded on-demand into spans that are placed inside grid's cells.
Imagine grid cells having <span id="foo_bar'></span> as content, and special ajax handlers are polling the backend for updated information and once available the spans are filled with it.
Now, in case I collapse some part of the grid and then re-exand them again I loose all automatically filled cell content, and am left with empty spans (which I started from in the first place).
I know the correct way is to setup a store and push all data into the store. But as I've mentioned above: I am porting quite a huge piece of legacy software to ExtJS, and I do not really have much choice here.
Is there a way to automagically push grid cell values to the store?
Update:
A grid is loaded with, suppose, 2000 cells (this can vary tremendously). Every cell contains various grades of HTML, mostly this is , but this can be pretty much anything (including several spans or divs in one cell). In the background there is a comet process pushing new data to the HTML page almost in real time. This data is populated to the corresponding SPANS and DIVs either based on their IDs or class or both.
What I want to achieve is that either:
a) the model for the grid is atomagically updated with the new html content of the cells (how can I achieve this)?
b) when collapsing/expanding tree's nodes the model data is NOT reloaded afresh.
Is either a or b possible? if so — how?
Just update your store when the 'special ajax handlers' successfully return values. In staid of manually messing with the dom.
so in the success callback do something like -> loadData()
Edit:
Seems like you are working with very bad legacy code :) If adding a simple line of code to the ajax handler is a tremendous effort.. You can however attach dom listeners, but it's very bad practice. Here are some events to listen to
Edit:
Here is an example of the use of how you could listen to dom events, it's rather a pure js solution but, meh.. it works..

Does pagination on static HTML table help improve performance

I have a big HTML table (~10K rows, 4 columns, text only) dumped from a database. I'm experiencing poor performance when opening it in Chrome/Firefox.
I do not have direct access to database, so it is impossible to load page by page. All data is static HTML.
Does pagination with some jQuery plugin help improve performance in this case? Any other suggestions?
When applicable, setting table-layout: fixed helps in reducing rendering time a lot. The slowness is mostly caused by the fact that in the default table layout method, the browser has to parse and process the entire table, calculating width requirements for all cells, before it can render any part of the table.
Fixed layout tells the browser to set column widths according to the first row (paying attention to any CSS that may apply to it). This may, of course, result in a mess, if the widths are not suitable for other rows. For a data table where rows are generally very similar, the widths can probably be set suitably.
This does not change the issue that very few people, if any, are going to read all the 10,000 rows. People will probably be looking for some specific data there. It might be better to set up a search form that lets the user get just what he wants.
I had a similar problem and made a jQuery plugin:
https://github.com/lperrin/infinitable
To use it, you can load all your data with Ajax call, turn it into a huge array, and pass it to the plugin.
It basically hides cells that are not visibles, while making it easy to sort or filter cells. There are other solutions to achieve that, but this one has no dependencies besides jQuery.
The project contains a demo with a table containing 100,000 elements.
Pagination would most certainly solve this problem. You could also try initially setting the table style to display: none. Although the pagination should likely take effect before the browser attempts to render the table.
You could also store the table in a separate html file, do an ajax call to the document, and implement live scrolling. Although, this depends on how you expect the user to explore the data. If jumping to a particular rage like 100-199 is useful, a paginated table would be ideal.

Categories

Resources