I updated my data grid from Kendo UI React Wrappers to new React package #progress/kendo-react-grid 0.3.0. In old jQuery grid version (or wrapped into React components) I was able to manipulate grid header (e.g.: set columnMenu filterable to false) or to define headerTemplate.
Documentation of new package does not mention anything about this. In package source files I found directory header which contains files GridFilterRow.js, GridHeader.js, GridHeaderRow.js, but there is no way (or, I didn't found it) to customize these components.
I wonder if there is any way to customize grid header in new rewritten version of Kendo UI Grid for React?
The FilterRow of the grid is not customizable in the 0.3.0 version, and this is why it is not mentioned in the documentation.
There is an issue logged in the official kendo-react repository about this:
Make Grid Filter Cells more customizable
For the current version, the filterable and filter settings can be controlled using the columns settings per each column. And there is property headerClassName that you can use for styling the cells.
Column/filter menu is not in the roadmap for now, but you can vote for it in the official feedback portal.
You can modify the header manually, using by adding an HTML element using Java Script after the grid renders, not a pretty solution but it will do the work while waiting for the official solution.
Here is what I did:
class Table extends React.Component {
constructor(props) {
super(props);
this.gridRef = React.createRef();
}
render() {
return (
<div ref={this.gridRef} >
<Grid
data={data}
onItemChange={itemChange}
cellRender={cellRender}
rowRender={rowRender}
editField="inEdit"
>
<GridToolbar>
</GridToolbar>
<Column title="Column Name" field="ProductName" width={300} locked={true}/>
<Column field="ProductID" title="Id" editable={false} />
<Column title="Units In Stock" editor="numeric" field="UnitsInStock" />
<Column title="First Ordered" editor="date" format="{0:d}" field="FirstOrderedOn" />
<Column editor="boolean" field="Discontinued" />
<Column title="Units In Stock" editor="numeric" field="UnitsInStock" />
<Column title="First Ordered" editor="date" format="{0:d}" field="FirstOrderedOn" />
<Column editor="boolean" field="Discontinued" />
</Grid>
</div>
);
}
componentDidMount(){
var ths = this.gridRef.current.getElementsByTagName('th');
for(var i = 0; i < ths.length; i++){
ths[i].appendChild( this.createColumnMenuIcon() );
}
}
createColumnMenuIcon(){
var icon = document.createElement('i');
icon.classList.add('fa');
icon.classList.add('fa-chevron-down');
icon.setAttribute("style", "position: absolute;top: 12px;right: 10px;");
icon.addEventListener('click', function(){
console.log('Click Menu');
})
return icon;
}
}
export default Table
Related
I have a question regarding react-admin. So I'm building this admin List which Hasura-graphQL. I am able to render Images with the ImageField component which I am using:
<ImageField label="Image" source="image" sortByOrder="DESC"/>
And which I have no problems rendering. But the issue comes when I need to render a video that comes in a URL from my graphQL schema. Something like this:
"video": "https://myappvideo.blob.core.windows.net/posts/post_93753139-524a-4c85-a0fc-d40b47bd95f5.mp4?se=2030-12-31&sp=rwdlac&sv=2018-03-28&ss=btf&srt=sco&sig=oeyHYsiWC79a1z7fcgsPPdJzeC499t%2BwPkbImcctpJE%3D",
"id": 471
},
{
"video": null,
"id": 493
},
{
"video": "https://myappvideo.blob.core.windows.net/posts/post_f9c59f2f-3d2e-4c63-ae1e-65e5324866ad.mp4?se=2030-12-31&sp=rwdlac&sv=2018-03-28&ss=btf&srt=sco&sig=oeyHYsiWC79a1z7fcgsPPdJzeC499t%2BwPkbImcctpJE%3D",
"id": 476
},[...]
How can render videos in my react-admin list? Something where I can show the videos and I can click and reproduce?
React-admin has a way to render Images but I can see something similar for videos.
Any help would be appreciated a lot!
EDIT
This is how I'm actually trying to make this work:
<Datagrid>
<TextField label="Post ID" source="id" sortByOrder="ASC" />
//I am using FileField for this, but it does not work
<FileField label="Content" source="video" rel="video" sortByOrder="ASC" />
<TextField label="Content Type" />
<UserSum source="id" />
<SimpleForm {...props} label="Flagged">
<ApproveData source="id" />
</SimpleForm>
<DateField label="Posted On" source="createdAt" showTime />
<PostListActionToolbar>
<ShowButton label="Details" color="secondary" />
<EditButton label="Archive" color="secondary" />
</PostListActionToolbar>
</Datagrid>
Ok, I just figure out how to do this. Indeed react-admin does not have a way to render videos. So in this case you'll have to create your own component.
Step 1
Is to create the function:
const VideoField = (props) => {
const record = useRecordContext(props);
return <video src={`${record.video}`} controls width="320" height="240"></video>;
}
In this case, you'll have to interpolate the video record inside the video tag. I added the controls and the width and height to add more view on the video
Step 2
You can add a default label into it like this:
VideoField.defaultProps = { label: 'Video' };
This is necessary since it will label your content on the top side of the list.
Step 3
Then add your function in to a component inside the datagrid and you'll be having something like this:
Add it like this on your datagrid
<Datagrid>
<TextField label="Post ID" source="id" sortByOrder="ASC" />
<VideoField source="video" />
<TextField label="Content Type" />
</Datagrid>
We have a Kendo React grid and we need to show the No record found the message when data is empty.
<Grid
sortable
filterable
expandField="expanded"
detail={props => <DetailComponent
{...props}
onChange={this.handleDetailTemplateChange}
changed={[]}
/>}
onExpandChange={this.expandChange}
pageable={this.state.pageable}
// scrollable="true"
editField="inEdit"
data={this.state.providersPage}
sort={this.state.sort}
onSortChange={this.handleSortChange}
filter={this.state.filter}
onFilterChange={this.handleFilterChange}
onPageChange={this.handlePageChange}
total={this.state.total}
skip={this.state.skip}
pageSize={this.state.pageSize}
onItemChange={this.handleProviderChange}
resizable>
<GridColumn field="affiliationRelationshipStatusName" title="Network Relationship" filterCell={this.CategoryFilterCell}
cell={NetworkRelationshipCell} width="245px"/>
<GridColumn field="address" title="Places" filterable={false} cell={NetworkPlaceCell}
width="245px"/>
</Grid>
See Kendo documentation but couldn't find any solution. Please suggest
The packages comes with GridNoRecords exported component, that you can place inside the grid. It will be rendered when there are no records.
Import it as you import the grid itself:
import { Grid, GridColumn, GridNoRecords } from '#progress/kendo-react-grid'
Then place it inside the grid, with some content inside it.
<Grid data={[]}>
<GridNoRecords>
There is no data available
</GridNoRecords>
<GridColumn field="id" />
<GridColumn field="name" />
</Grid>
The above example is from the official documentation. I believe this is what you are looking for.
I'm using react-admin 2.6.2 and trying currently to edit the layout of the List view. At first I wanted to remove action buttons completely, and I found the answer here at Stackoverflow. I thought, that using empty CardActions would be enough, but there's still empty ListToolbar taking space before my <List> starts. The toolbar is created by List automatically, is there any way to for example edit styles of that toolbar so I could hide it or set the height to 0px?
I guess one option is to create my custom List.js based on this, but it would be best to use the original source files, so they are also updated when there are new updates to react-admin.
JS code:
const NoneActions = props => (
<CardActions />
);
class DemoList extends Component {
render() {
return (
<div>
<List
{...props}
actions={<NoneActions />}
>
<Datagrid>
<TextField source="name" />
<ShowButton />
</Datagrid>
</List>
</div>
);
}
}
Here's the toolbar in DOM:
<div class="MuiToolbar-root-519 MuiToolbar-regular-521 MuiToolbar-gutters-520 ListToolbar-toolbar-293">
try: <List actions={null} {...props}> the empty space before the list disappears.
I've created an admin panel in React.js using admin-on-rest. I have a page showing a user list pulling data from an api. I need to add a custom column at the end of each row of that table that will display a progress bar for each user.
I'm using a module called rc-progress to generate the progress bar. Here's an example display on a separate page currently from the user list:
import React from 'react';
import { Line } from 'rc-progress';
var Progress = React.createClass({
render: function render() {
return (
<Line percent="40" strokeWidth="1" strokeColor="#38bcd5" />
);
}
});
export default Progress;
I'm not sure how to append a custom column to a Datagrid in admin-on-rest to add in that progress bar.
Here's the code I have for the User list which is displaying the data from the API correctly. I've added a comment where I'd want to add the progress bar:
import React from 'react';
import { List, Datagrid, TextField} from 'admin-on-rest';
import { Line } from 'rc-progress';
export const UserList = (props) => (
<List {...props}>
<Datagrid>
<TextField source="firstName" />
<TextField source="lastName" />
<TextField source="email" />
<TextField source="phone" />
<TextField source="type" />
//I'd like to add the progress bar below:
//<Line percent="40" strokeWidth="1" strokeColor="#38bcd5" />
</Datagrid>
</List>
);
export default UserList;
Any help is much appreciated!
Update (Solution)
So on the recommendation of Gildas I've tried to use the FunctionField. Here is the working version of the code. (The progress bar has hard-coded values right now)
import React from 'react';
import { List, Datagrid, TextField} from 'admin-on-rest';
import { Line } from 'rc-progress';
import { FunctionField } from 'admin-on-rest'
export const UserList = (props) => (
<List {...props}>
<Datagrid>
<TextField source="firstName" />
<TextField source="lastName" />
<TextField source="email" />
<TextField source="phone" />
<TextField source="type" />
//Here is the working version below:
<FunctionField label="Progress" render= {function render() { return ( <Line percent="40" strokeWidth="1" strokeColor="#38bcd5" />);}} />
</Datagrid>
</List>
);
export default UserList;
Here's a current screenshot:
The FunctionField should do the trick: https://marmelab.com/admin-on-rest/Fields.html#functionfield
If not, have you tried following the custom field documentation ?
I am trying to combine a custom CSS table with the react virtualized window scroller. I currently can get the table to display, but am having trouble figuring out how to combine styling to that table, or add any logic to the table rows.
<WindowScroller>
{({ height, isScrolling, onChildScroll, scrollTop }) => (
<Table
autoHeight
width={1000}
height={700}
headerHeight={20}
rowHeight={30}
isScrolling={isScrolling}
onScroll={onChildScroll}
rowCount={table.length}
scrollTop={scrollTop}
rowGetter={({ index }) => table[index]}
>
<Column
label='Item1'
dataKey='item1'
width={150}
/>
<Column
width={200}
label='item2'
dataKey='item2'
/>
<Column
width={200}
label='item3'
dataKey='item3'
/>
<Column
width={150}
label='item4'
dataKey='item4'
/>
<Column
width={200}
label='item5'
dataKey='item5'
/>
</Table>
)}
</WindowScroller>
Definitely review the docs. You'll likely be passing both some type of style props and event props to the components - so you need to understand how those components define and accept those props. This is only possible by reviewing the documentation of the library.
EDIT:
Here are the propTypes for the <Table /> component:
https://github.com/bvaughn/react-virtualized/blob/master/docs/Table.md
You'll see that it accepts custom event handlers like onRowClick but also style props like rowStyle