Open In App

React.js Blueprint Table ColumnHeaderCell JS API

React.js Blueprint is a front-end UI toolkit. It is very optimized and popular for building interfaces that are complex data-dense for desktop applications.

The table component allows the user to display rows of data. We can use the following approach in ReactJS to use the ReactJS Blueprint Table Component.



Table Props:

 



ColumnHeaderCell Props:

Syntax:

<ColumnHeaderCell> ... </ColumnHeaderCell>

Prerequisite: 

Creating React Application And Installing Module:

Step 1: Create a React application using the following command:

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command:

cd foldername

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @blueprintjs/core
npm install --save @blueprintjs/table

Project Structure: It will look like the following.

 

Example 1: We are using the table component to show data in the form of a table where numRows specified the number of rows, here we have shown two Columns with headers and have passed our custom sampleColumn function and passed index props which returns the Column header cells with the index. 

App.js




import React from 'react'
import '@blueprintjs/core/lib/css/blueprint.css';
import '@blueprintjs/table/lib/css/table.css';
import { Column, Table, ColumnHeaderCell } 
    from "@blueprintjs/table";
  
function App() {
  
    const sampleColumn = (index) => {
        return <ColumnHeaderCell>
            Column {index}
           </ColumnHeaderCell>
    };
    return (
        <div style={{
            display: 'block',
            width: 390,
            padding: 30
        }}>
            <h4>
                ReactJS Blueprint Table JS API ColumnHeaderCell
            </h4>
            <Table numRows={5}>
                <Column
                    columnHeaderCellRenderer={sampleColumn} />
                <Column
                    columnHeaderCellRenderer={sampleColumn} />
            </Table>
        </div>
    );
}
  
export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: In the above code, we are now creating two custom functions naming it as sampleColumnOne and sampleColumnTwo. In the first function, we are passing the loading props, in the second one we are passing the name props and have added some inline style to it.

App.js




import React from 'react'
import '@blueprintjs/core/lib/css/blueprint.css';
import '@blueprintjs/table/lib/css/table.css';
import { Column, Table, ColumnHeaderCell } 
    from "@blueprintjs/table";
  
function App() {
  
    const sampleColumnOne = () => {
        return <ColumnHeaderCell
            loading
        >Column </ColumnHeaderCell>
    };
  
    const sampleColumnTwo = (index) => {
        return <ColumnHeaderCell
            name="Name"
            style={{ color: "green" }}
        />
    };
  
    return (
        <div style={{
            display: 'block',
            width: 390,
            padding: 30
        }}>
            <h4>
                ReactJS Blueprint Table JS API ColumnHeaderCell
            </h4>
            <Table numRows={5}>
                <Column
                    columnHeaderCellRenderer={sampleColumnOne} />
                <Column
                    columnHeaderCellRenderer={sampleColumnTwo} />
            </Table>
        </div>
    );
}
  
export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Reference: https://blueprintjs.com/docs/versions/1/#table-js.columnheadercell


Article Tags :