CouchView
A jquery plug-in lets you create a grid using either tables or divs & spans. I originally developed it to work with CouchDB but it will work with any JSON source.
Install / Use
/learn @thanos/CouchViewREADME
h1. Couch-View
h2. Overview
This JQuery plugin lets you map a CouchDb view to a html grid. That’s it. I looked at the other JQuery grid plug-ins – many of which a really great – But I couldn't get them working and since I’m lazy I wrote this specialized plug-in.
So here are its features:
* It's HTML agnostic. Y ou can use tables or divs or any HTML to layout your data.
* You can view JSON data from any source – such as CouchDB.
* You get column sorting.
* You get paging paging
* It's compatible with JEditable. So you can edit your data.
* Really small – Currently under 3K.
* Coded in a clean fashion so you can subclass header/body or footer generation and the loading and saving of data.
h2. A Quick Guide with HTML Tables
h4. Before I Embark...
Before I embark in trying to explain how to use this plug-in, I'm going to explain the JSON datastructure that it expects by default. As an example I will use a real database of more than 40K electric power usages records. Here is one of its documents:
<pre>
{
_id: "4da96f65dfecf6edd329269c3799de60",
_rev: "1-3a49c260576c26c758742c8842d5b9ca",
loadAvgHourlyNI: 8404.7,
hourEnd: 1,
loadAvgHourlyDUQ: 1263.2,
loadAvgHourlyDAY: 1392.2,
loadAvgHourlyMIDATL: 22126.6,
loadAvgHourlyDOM: 7162.4,
loadAvgHourlyAEP: 10855.8,
loadAvgHourlyAP: 3834.5,
date: "2010-04-05",
id: "pjm-20100405-01"}
</pre>
I'll start with using this view:
<pre>
{
"_id": "_design/tests",
"_rev": "2-9712dcb1e76a5cc7ab0e0e0b5bf7a70a",
"language": "javascript",
"views": {
"id": {
"map": "function(doc) {\n emit(doc.id, null);\n}"
}
}
}
</pre>
So <a href="http://69.164.211.38:8080/mydb/_design/tests/_view/id?limit=2">http://69.164.211.38:8080/mydb/_design/tests/_view/id?limit=2&include_docs=true</a>
will give you:
<pre>
{
"total_rows":24,
"offset":0,
"rows":[
{
"id":"4da96f65dfecf6edd329269c3799de60",
"key":"pjm-20100405-01",
"value":{"_id":"4da96f65dfecf6edd329269c3799de60","_rev":"1-3a49c260576c26c758742c8842d5b9ca","loadAvgHourlyNI":8404.7,"hourEnd":1,"loadAvgHourlyDUQ":1263.2,"loadAvgHourlyDAY":1392.2,"loadAvgHourlyMIDATL":22126.6,"loadAvgHourlyDOM":7162.4,"loadAvgHourlyAEP":10855.8,"loadAvgHourlyAP":3834.5,"date":"2010-04-05","id":"pjm-20100405-01"}
},
{"id":"6339d2c104c222a31872ac400f2a5bb9","key":"pjm-20100405-02","value":{"_id":"6339d2c104c222a31872ac400f2a5bb9","_rev":"1-0e0e84e6485fd61bf830cd01df406393","loadAvgHourlyNI":8011.1,"hourEnd":2,"loadAvgHourlyDUQ":1242.6,"loadAvgHourlyDAY":1347.6,"loadAvgHourlyMIDATL":21215.9,"loadAvgHourlyDOM":6819,"loadAvgHourlyAEP":10485.4,"loadAvgHourlyAP":3808,"date":"2010-04-05","id":"pjm-20100405-02"}}
]
}
</pre>
</li>
<li>
<H4>What to Include</h4>
Include jquery in your HTML header. You can use googleapis for this. Then add jquery.couchview.js.
<pre>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="jquery.couchview.js"></script>
</pre>
</li>
<li>
<h4>Creating your Template</h4>
Code an example table with one row of dummy data:
<table><tr><td>
<pre>
<table id="table-1" bgcolor="gray">
<tbody>
<tr bgcolor="lightgray">
<th>Id</th>
<th>Date</th>
<th>Hour</th>
<th>Load</th>
</tr>
<tr bgcolor="white" class="data-row">
<td>pjm-20100405-24</td>
<td>05/04/2010</td>
<td>24</td>
<td>1686.4</td>
</tr>
</tbody>
</table>
</pre>
</td></tr><tr>
<td>
<table bgcolor="gray">
<tbody>
<tr bgcolor="lightgray">
<th>Id</th><th>Date</th><th>Hour</th><th>Load</th>
</tr>
<tr bgcolor="white" class="data-row">
<td>test_id</td><td>05/04/2010</td><td>24</td><td>1686.4</td>
</tr>
</tbody>
</table>
</td></tr></table>
</li>
<li>
<h4>Apply the plugin</H4>
Apply the plugin to a class that you will use for your test grid. In these examples I will use 'grid-test'. For options i've set the url to our database's view design document, the view and a page size of 4 lines.
<pre>
<html lang="en">
<head>
<title>Couch View</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="jquery.couchview.js"></script>
<script>
$(document).ready(function() {
$(".grid-test").couchview({
url: "http://69.164.211.38:8080/mydb/_design/tests/_view/",
limit: 4,
view:'id'
});
});
</script>
</head>
</pre>
</li>
<li> <h4>Enliven your Table</h4>
<ol>
<li> Add to the parent container, in this case table, the class 'grid-test', give it also an id.
<pre>
<table id="table-1" bgcolor="gray" class="grid-test" >
</pre>
</li>
<li>
Now add to each data cell, in this case the table's TD element the class 'field' and a id attribute set to teh name of a field form the document:
In this example we will want to show only id, date, hour, and loadAvgHourlyDAY.
<pre>
<table id="example-1" bgcolor="gray" class="grid-test"> <tbody class="data-body"> <tr bgcolor="lightgray" class="header-row"> <th>Id</th> <th>Date</th> <th>Hour</th> <th>Load</th> </tr> <tr bgcolor="white" class="data-row"> <td class="field" id="id">pjm-20100405-24</td> <td class="field" id="date">05/04/2010</td> <td class="field" id="hourEnd" >24</td> <td class="field" id="loadAvgHourlyDAY">1686.4</td> </tr> </tbody> </table> </pre> <table id="example-1" bgcolor="gray" class="grid-test"> <tbody class="data-body"> <tr bgcolor="lightgray" class="header-row"> <th id="id" class="column" >Id</th> <th id="date" class="column" >Date</th> <th id="hourEnd" class="column" >Hour</th> <th id="loadAvgHourlyDAY" class="column" >Load</th> </tr> <tr bgcolor="white" class="data-row"> <td class="field" id="id">pjm-20100405-24</td> <td class="field edit" id="date">05/04/2010</td> <td class="field edit" id="hourEnd" >24</td> <td class="field edit" id="loadAvgHourlyDAY">1686.4</td> </tr> </tbody> </table> </li> </ol> <li> <h4>Add a Pager</h4> Now we will add the pager. Here are the relevant classes: <table bgcolor="lightgray" > <tr bgcolor="white" ><th>class</th><th>Use</th></tr> <tr bgcolor="white" ><td>pager-first</td><td>Creates a clickable element that requests the first page data</td></tr> <tr bgcolor="white" ><td>pager-prev-page</td><td>Creates a clickable element that requests the previous page data</td><
Related Skills
bluebubbles
351.2kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
gh-issues
351.2kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
healthcheck
351.2kHost security hardening and risk-tolerance configuration for OpenClaw deployments
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
