2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 17:34:04 +00:00
books/docs/client/lists.md

54 lines
1.1 KiB
Markdown
Raw Normal View History

2018-01-10 12:49:52 +00:00
# Lists
A list object handles object listing and paging, for a standard model.
### Example
```js
2018-01-16 06:09:17 +00:00
const Page = require('frappejs/frappe/client/view/page');
const List = require('frappejs/frappe/client/view/list');
2018-01-10 12:49:52 +00:00
// create a new page
let todo_list = new Page('ToDo List');
// init a new list
2018-01-16 06:09:17 +00:00
todo_list.list = new List({
2018-01-10 12:49:52 +00:00
doctype: 'ToDo',
parent: this.todo_list.body
});
todo_list.on('show', () => {
// refresh on show
todo_list.list.run();
})
```
## Creating a new List
You can create a new list object by passing the `DocType` and the parent element of the list
## Refreshing
2018-01-30 12:03:04 +00:00
To reload the list, call the `run` method
## Extending
Lists can be extended by defining a client module for the doctype, similar to forms
```js
const BaseList = require('frappejs/client/view/list');
class ToDoList extends BaseList {
2018-02-08 12:28:51 +00:00
getFields() {
2018-01-30 12:03:04 +00:00
return ['name', 'subject', 'status'];
}
2018-02-08 12:28:51 +00:00
getRowHTML(data) {
2018-01-30 12:03:04 +00:00
let symbol = data.status=="Closed" ? "✔" : "";
return `<a href="#edit/todo/${data.name}">${symbol} ${data.subject}</a>`;
}
}
module.exports = {
List: ToDoList
}
```