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

can you add an example with function components and hooks #68

Open
Amishmaqbool opened this issue Jun 26, 2021 · 5 comments
Open

can you add an example with function components and hooks #68

Amishmaqbool opened this issue Jun 26, 2021 · 5 comments

Comments

@Amishmaqbool
Copy link

No description provided.

@madooei
Copy link

madooei commented Jul 5, 2021

Does this help?

import React, { useState } from "react";
import ReactFilterBox, { SimpleResultProcessing } from "react-filter-box";

const options = [
  {
    columnField: "Name",
    type: "text",
  },
  {
    columnField: "Description",
    type: "text",
  },
  {
    columnField: "Status",
    type: "selection", // when using type selection, it will automatically suggest all possible values
  },
  {
    columnText: "Email @",
    columnField: "Email",
    type: "text",
  },
];

function Demo(props) {
  const [data, setData] = useState([]); // pass your data in here instead of empty array

  const onParseOk = (expressions) => {
    const newData = new SimpleResultProcessing(options).process(
      data,
      expressions
    );
    // your new data here, which is filtered out of the box by SimpleResultProcessing
    setData(newData);
  };

  return (
    <>
      <ReactFilterBox
        data={data}
        options={options}
        onParseOk={onParseOk}
      />
    </>
  );
}

export default Demo;

@Amishmaqbool
Copy link
Author

does it runs on next js

@madooei
Copy link

madooei commented Jul 6, 2021

does it runs on next js

I don't know. try it!

@Amishmaqbool
Copy link
Author

nope this package doesn't support next js or to be more precise SSR Frontend architecture

@ChandraAvira
Copy link

Does this help?

import React, { useState } from "react";
import ReactFilterBox, { SimpleResultProcessing } from "react-filter-box";

const options = [
  {
    columnField: "Name",
    type: "text",
  },
  {
    columnField: "Description",
    type: "text",
  },
  {
    columnField: "Status",
    type: "selection", // when using type selection, it will automatically suggest all possible values
  },
  {
    columnText: "Email @",
    columnField: "Email",
    type: "text",
  },
];

function Demo(props) {
  const [data, setData] = useState([]); // pass your data in here instead of empty array

  const onParseOk = (expressions) => {
    const newData = new SimpleResultProcessing(options).process(
      data,
      expressions
    );
    // your new data here, which is filtered out of the box by SimpleResultProcessing
    setData(newData);
  };

  return (
    <>
      <ReactFilterBox
        data={data}
        options={options}
        onParseOk={onParseOk}
      />
    </>
  );
}

export default Demo;

HI, Is there a way to clear the input filed data after the search or on clicking the custom clear button.

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

3 participants