@blueprintjs/table how to navigate using arrow/tab keys

877 views Asked by At

I would like to navigate @blueprintjs/table using arrow/tab keys. I followed these document, but couldn't find any solution. Could anyone help with a sample code / solution.

My current component is as follows.

import React, { Component } from 'react';
import { EditableCell, Column, Table } from "@blueprintjs/table";

class TestComponent extends Component {

    constructor(props) {
        super(props);
        this.renderCell = this.renderCell.bind(this);
    }
renderCell (rowIndex, columnIndex)  {
    const value = null;
    return (
        <EditableCell alue={value == null ? "" : value}/>
    );
}
    render() {
        const columns = ["Please", "Rename", "Me"].map((_ , index) => {
            return (
                    <Column key={index} cellRenderer={this.renderCell} enableFocus="true"/>
            );
    });
        return (
            <Table numRows={7} enableFocus="true">{columns}</Table>
        );
    }
}
export default TestComponent;
1

There are 1 answers

0
Prince Francis On

I got the solution, so answering my own question.

we should use enableFocusedCell="true" for the Table component, to enable navigation using arrow/tab keys.

Please find the sample code below.

first import css

import "@blueprintjs/table/lib/css/table.css";

then create a component like follows

import React, { Component } from 'react';
import { Cell, Column, Table } from "@blueprintjs/table";
const cellRenderer = (rowIndex) => {
    return <Cell>{`$${(rowIndex * 10).toFixed(2)}`}</Cell>
};
class LedgerGroup extends Component {

    constructor(props) {
        super(props);
    }


    render() {
        return (
            <Table numRows={10} enableFocusedCell="true">
                <Column name="Dollars 1" cellRenderer={cellRenderer}/>
                <Column name="Dollars 2" cellRenderer={cellRenderer}/>
            </Table>
        );
    }
}
export default LedgerGroup;