Giter VIP home page Giter VIP logo

Comments (3)

fuchsberger avatar fuchsberger commented on May 29, 2024 1

a multi-column sort can easily be achieved when using remote={ filter: true }. Here is my implementation (in case it helps):

MyComponent.js

import React from "react"
import { connect } from 'react-redux'
import SmartTable from '../../components/layout/smart_table'

class MyComponent extends React.Component {

  constructor(props){
    super(props)

    this.handleSearchChange = this.handleSearchChange.bind(this)
    this.handleTableChange = this.handleTableChange.bind(this)

    this.columns = [{
      dataField:        'id',
      hidden:           true,
      text:             'id'
    },{
      dataField:        'name',
      text:             'Name',
      sort:             true
    }, {
      dataField:        'email',
      text:             'Email',
      sort:             true
    }];

    this.state = {
      data:           this.props.users || [],
      search:         ''
    }
  }

  handleSearchChange(e){
    this.handleTableChange('filter', { search: e.target.value })
  }

  handleTableChange(type, { search }){
    setTimeout(() => {
      const result = (!search || search.length === 0) ? this.props.users
      : this.props.users.filter((row) => {
        const searchstring = search.toLowerCase()
        return (
          row.name.toLowerCase().toString().indexOf(searchstring) > -1 ||
          row.email.toLowerCase().toString().indexOf(searchstring) > -1
        );
      });
      this.setState({ data: result, search });
    }, 500);
  }

  render(){
    return (
      <Container>
        <SmartTable
          columns       = { this.columns }
          data          = { this.state.data }
          keyField      = 'id'
          onTableChange = { this.handleTableChange }
        />
        <Input
          name        =  "search"
          onChange    = { this.handleSearchChange }
          placeholder = 'Search...'
          type        = "search"
        />
      </Container>
    );
  }
}

const mapStateToProps = function(store) {
  return { users: store.admin.users }
}
export default connect(mapStateToProps)(MyComponent)

SmartTable.js

import React from 'react'
import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory from 'react-bootstrap-table2-filter';

const SmartTable = (props) => {
  const { columns, data, keyField, onTableChange } = props

  return (
    <BootstrapTable
      columns       = { columns }
      data          = { data }
      filter        = { filterFactory() }
      keyField      = { keyField }
      onTableChange = { onTableChange }
      remote        = {{ filter: true }}
    />
  );
}

export default SmartTable

from react-bootstrap-table2.

AllenFang avatar AllenFang commented on May 29, 2024

@Chun-MingChen ask me if you have any concern or questions

from react-bootstrap-table2.

pastinepolenta avatar pastinepolenta commented on May 29, 2024

@fuchsberger I am confused, that example is about filtering not sorting, right?

@AllenFang Any plans for this feature?

from react-bootstrap-table2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.