Skip to content

Commit d54bc79

Browse files
authored
Documentation improvement
1 parent b1ec5a1 commit d54bc79

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

README.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Laravel API for React Dynamic Data Table
22

3-
*Work in progress*
4-
53
This package provides a Laravel API endpoint responder for the
64
[React Dynamic Data Table](https://github.com/langleyfoxall/react-dynamic-data-table)
75
component.
@@ -14,7 +12,11 @@ composer require langleyfoxall/react-dynamic-data-table-laravel-api
1412

1513
## Usage
1614

17-
Example syntax:
15+
First, create a new route in your API routes file for the data table response, and point it to a controller.
16+
17+
In this controller method, create a new `DataTableResponder` passing it the model you wish to return data about, and the provided instance of the `Request` object. You can optionally specify changes to the query (such as sorting, or filtering) using the `query` method. You can also change number of records shown per page with the `setPerPage` method.
18+
19+
See the example usage below.
1820

1921
```php
2022
use App\User;
@@ -34,3 +36,27 @@ class UsersController extends Controller
3436
}
3537
}
3638
```
39+
40+
In your frontend code, you can now use the [React Dynamic Data Table](https://github.com/langleyfoxall/react-dynamic-data-table) package's `AjaxDynamicDataTable` component to display a table of this data. The API route previously defined should be passed to this component as the `apiUrl` prop.
41+
42+
An example usage is shown below.
43+
44+
```jsx
45+
import React, { Component } from 'react';
46+
import ReactDOM from 'react-dom';
47+
import AjaxDynamicDataTable from "@langleyfoxall/react-dynamic-data-table/dist/AjaxDynamicDataTable";
48+
49+
export default class Example extends Component {
50+
render() {
51+
return (
52+
<div className="container">
53+
<AjaxDynamicDataTable apiUrl={'/api/users/data-table'}/>
54+
</div>
55+
);
56+
}
57+
}
58+
59+
if (document.getElementById('example')) {
60+
ReactDOM.render(<Example />, document.getElementById('example'));
61+
}
62+
```

0 commit comments

Comments
 (0)