Comments (5)
from datasette import hookimpl
JS = """
document.addEventListener('datasette_init', function(ev) {
ev.detail.registerPlugin('column-name-plugin', {
version: 0.1,
makeColumnActions: (columnDetails) => {
console.log({columnDetails});
const numericColumns = Array.from(
document.querySelectorAll('[data-column-type="float"],[data-column-type="integer"]')
).filter(el => el.dataset.isPk != "1").map((el) => el.dataset.column);
console.log({numericColumns});
if (columnDetails.columnType == 'float' || columnDetails.columnType == 'integer') {
const sql = `select sum(${columnDetails.columnName}) from {table}`;
return [
{
label: 'Sum column',
onClick: () => {
location.href = '/{database}?sql=' + encodeURIComponent(sql);
}
}
];
}
if (columnDetails.columnType == 'text' && numericColumns.length) {
// Add options for every other numeric column
return numericColumns.map((name) => ({
label: 'Sum by this: ' + name,
onClick: () => {
const sql = `select ${columnDetails.columnName}, sum(${name}) from {table} group by ${columnDetails.columnName}`;
location.href = '/{database}?sql=' + encodeURIComponent(sql);
}
}));
}
return [];
}
});
});
"""
@hookimpl
def extra_body_script(database, table):
if database and table:
return {
"script": JS.replace("{database}", database).replace("{table}", table)
}
the menu seems to be reused, so if you click a text column first it shows up incorrectly on the following clicks to float columns.
from datasette.
Bug is in here somewhere:
datasette/datasette/static/table.js
Lines 88 to 239 in 6ec0081
from datasette.
Here is the code that creates that menu only once:
datasette/datasette/static/table.js
Lines 245 to 250 in 6ec0081
It should be created on every click to open the menu.
from datasette.
I just reset it with menu.innerHTML = DROPDOWN_HTML
.
from datasette.
Plugin is now released that uses this fix: https://pypi.org/project/datasette-column-sum/
from datasette.
Related Issues (20)
- datasette.permission_allowed() should consider all checks, not just the last returned HOT 6
- Release notes for Datasette 1.0a9
- database.execute_write_fn() should default to running in a transaction HOT 6
- Incorrect display of permissions in permission testing tool HOT 2
- POST to /-/insert with "replace": true should require update-row HOT 5
- Release notes for 1.10a11 HOT 1
- Database and table action menus should appear next to the cog icon HOT 9
- `query_actions` plugin hook - like `table_actions` and `database_actions` for the query/canned query page HOT 2
- Document and make stable `derive_named_parameters` utility function HOT 2
- Ditch the "form label" styles
- New action button displayed too close to metadata HOT 1
- "does not contain" table filter HOT 2
- `internal.db` database is written to WAY too often HOT 6
- Fix httpx app shortcut deprecation warning
- Permissions defined in datasette.yml do not correctly obey the veto rule HOT 1
- /fixtures/-/explain is broken on latest.datasette.io HOT 2
- Optional descriptions on table/query/database action menu items HOT 2
- Automatically hide type=shadow tables in SQLite 3.37 or higher HOT 1
- view_actions() hook, to avoid showing table actions on view pages that don't work HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datasette.