Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOTHING IS WORKING. #46

Open
logysis opened this issue Jul 8, 2017 · 13 comments
Open

NOTHING IS WORKING. #46

logysis opened this issue Jul 8, 2017 · 13 comments

Comments

@logysis
Copy link

logysis commented Jul 8, 2017

Sorting, Paging, Filtering all don't work. Wasted half day on it.

@UkiMiawz
Copy link

confirmed, I tried to work on the example also, copy and paste the exact same codes, doesn't work

@logysis
Copy link
Author

logysis commented Jul 10, 2017

@UkiMiawz the only way to get it working is write your own sort/paging/filter handlers.

@logysis
Copy link
Author

logysis commented Jul 10, 2017

@hyojin, can I make the filter section displayed by default?

@hyojin
Copy link
Owner

hyojin commented Aug 1, 2017

@logysis I'm going to add the props which can handle the search bar. #44

@advance512
Copy link
Contributor

Great news @hyojin

@logysis
Copy link
Author

logysis commented Aug 8, 2017

Hi, how do you simulate a click on the cell in an Enzyme test?

@hyojin
Copy link
Owner

hyojin commented Aug 9, 2017

@logysis please check this :)

@logysis
Copy link
Author

logysis commented Aug 17, 2017

@hyojin can you make filter section displayed by default with some value in it?

@hyojin
Copy link
Owner

hyojin commented Aug 17, 2017

@logysis yes, you can use props, headerToolbarMode and filterValue.
here is example

@logysis
Copy link
Author

logysis commented Aug 17, 2017

@hyojin thank you!

@logysis
Copy link
Author

logysis commented Aug 17, 2017

@hyojin just wondering, when are you going to release a version with built-in paging/sort/filter?

@logysis
Copy link
Author

logysis commented Aug 17, 2017

@hyojin another question, is there a way to place the cursor in search box by default?

@michalpokojski
Copy link

my implementation of sort, filter and pagination :

import DataTables from 'material-ui-datatables'
import users from '../data/users.json'
import { sortByStringAscending, sortByStringDescending } from '../helpers/sorting'
import { TABLE_COLUMNS_USERS } from '../constants/tableColumnsSpecifications'

class Users extends Component {
  state = {
    searchPhrase: "",
    page: 1,
    rowSize: 10,
  }

  handleFilter = value => {
    this.setState({
      searchPhrase: value
    })
  }

  handlePreviousPageClick = () => {
    this.setState({page: this.state.page - 1})
  }

  handleNextPageClick = () => {
    this.setState({page: this.state.page + 1})
  }

  handleRowSizeChange = (rowSizeIndex, rowSize) => {
    this.setState({page: 1, rowSize});
  }

  render() {

    let data = sortByStringAscending([...users], 'email')
      .filter(row =>
        row.email.includes(this.state.searchPhrase) ||
        row.lastName.includes(this.state.searchPhrase) ||
        row.firstName.includes(this.state.searchPhrase))

    let displayData = data.slice(this.state.rowSize * (this.state.page - 1), this.state.rowSize * (this.state.page))

    const handleSort = (key, order) => order === 'desc' ? sortByStringDescending(displayData, key) : sortByStringAscending(displayData, key)

    return (
      <DataTables
        height={'auto'}
        showRowHover={true}
        columns={TABLE_COLUMNS_USERS}
        data={displayData}
        showCheckboxes={false}
        onSortOrderChange={handleSort}
        showHeaderToolbar={true}
        showHeaderToolbarFilterIcon={false}
        initialSort={{column: 'email', order: 'asc'}}
        onFilterValueChange={this.handleFilter}
        headerToolbarMode={'filter'}
        count={data.length}
        page={this.state.page}
        rowSize={this.state.rowSize}
        onPreviousPageClick={this.handlePreviousPageClick}
        onNextPageClick={this.handleNextPageClick}
        onRowSizeChange={this.handleRowSizeChange}
      />
    )
  }
}

export default Users
/////////////////////////////////////////////////////////////////////
and now for COLUMNS : 
/////////////////////////////////////////////////////////////////////
export const TABLE_COLUMNS_USERS = [
  {
    key: 'firstName',
    label: 'First Name',
    sortable: true
  }, {
    key: 'lastName',
    label: 'Last Name',
    sortable: true
  }, {
    key: 'email',
    label: 'Email',
    sortable: true
  }, {
    key: 'type',
    label: 'Type',
    sortable: true
  },
]
/////////////////////////////////////////////////////////////////////
and sort logic : 
/////////////////////////////////////////////////////////////////////
export const sortByStringAscending = (array, condition)  => array.sort((a, b) => a[condition].localeCompare(b[condition]))
export const sortByStringDescending = (array, condition)  => array.sort((a, b) => b[condition].localeCompare(a[condition]))```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants