An open API service indexing awesome lists of open source software.

https://github.com/jongacnik/kirby2-index-field

Kirby field for displaying pages as a datatable
https://github.com/jongacnik/kirby2-index-field

Last synced: 12 months ago
JSON representation

Kirby field for displaying pages as a datatable

Awesome Lists containing this project

README

          

# Kirby Index Field

Kirby field which displays pages (or files) as a [datatable](https://datatables.net/).

This is useful for navigating large-ish sets of items with filtering and sorting. Enables Kirby to be used a little more like a database. Pairs nicely with [kirby-hidebar-field](https://github.com/jongacnik/kirby-hidebar-field).

![Preview](https://github.com/jongacnik/kirby-index-field/blob/master/preview.png?raw=true)

## Examples

Show an index of pages children:

```yaml
pageindex:
label: Items
type: index
options: children
```

Show an index of pages files:

```yaml
pageindex:
label: Items
type: index
options: files
```

## Options

Similar to Kirby's [Select Field](https://getkirby.com/docs/cheatsheet/panel-fields/select), you use the `options` parameter to specify what the index should be populated with. All Dynamic Options from the Select Field can be used:

Option | Description
--- | ---
children | Index of all children
visibleChildren | Index of all visible children
invisibleChildren | Index of all invisible children
grandchildren | Index of all grandchildren
visibleGrandchildren | Index of all visible grandchildren
invisibleGrandchildren | Index of all invisible grandchildren
siblings | Index of all siblings
visibleSiblings | Index of all visible siblings
invisibleSiblings | Index of all invisible siblings
index | Index of all descendants
pages | Index of all pages of the site
files | Index of all files of the page
images | Index of all images of the page
documents | Index of all documents of the page
videos | Index of all videos of the page
audio | Index of all audio files of the page
code | Index of all code files of the page
archives | Index of all archives of the page

## Query

The Index Field also supports a version of the Select Field `query` parameter to generate more complex indexes of pages/files:

```yaml
pageindex:
label: Items
type: index
options: query
query:
page: blog
fetch: children
template: article
```

Where `page` is the [uid](https://getkirby.com/docs/cheatsheet/page/uid) of the desired page, and `fetch` is one of the [`options`](#options) above.

## Columns

By default, only a Title column (showing a page `title` or file `filename`) will be shown. You specify what columns should appear using the `columns` parameter. The first column determines the initial sort.

```yaml
pageindex:
label: Items
type: index
options: children
columns:
title: Title
date: Date
uid: Slug
```

The key specifies which property of the [page/file json](https://getkirby.com/docs/cheatsheet/page/to-json) should be fetched. The value specifies the title of the column. The following example will show a column labeled **Title** and the property `title` from each item's json representation:

```yaml
title: Title
```

### Column Options:

You can set a few options on a per column basis.

#### Column Width

```yaml
columns:
title:
label: Title
width: 100
uid: Slug
```

#### Column Class

```yaml
columns:
title:
label: Title
class: classname
uid: Slug
```

#### Column Sort-ability

```yaml
columns:
title:
label: Title
sort: false
uid: Slug
```

#### Column Visibility

```yaml
columns:
title:
label: Title
visible: false
uid: Slug
```

## Filter Data

A custom filter can be applied to the data before it is put out as a json response. This is perfect if you need to modify some of the data for presentation, change columns, etc.

Create a simple plugin `site/plugins/mydatafilters/mydatafilters.php`:
```php