question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting Columns with JSON? (QUESTION/ISSUE)

See original GitHub issue

Is it possible to set the columns property with JSON? Example below shows setting the data with AJAX JSON data but can it be done for the columns as well?

 $table.bootstrapTable({
                filterControl: true,
                disableUnusedSelectOptions: true,
                data: data,
                height: getHeight(),
                search: true,
                columns: [{
                    field: 'selected',
                    checkbox: true,
                    align: 'center'
                },

I have tried with this JSON data and no columns show up.

[
{"field":"selected","checkbox":true,"align":"center","title":null,"formatter":null,"sortable":false,"filterControl":null,"filterControlPlaceholder":null,"filterStrictSearch":false},

{"field":null,"checkbox":false,"align":"center","title":"Actions","formatter":"actionsFormatter","sortable":false,"filterControl":null,"filterControlPlaceholder":null,"filterStrictSearch":false},

{"field":"id","checkbox":false,"align":"center","title":"ID","formatter":null,"sortable":true,"filterControl":"input","filterControlPlaceholder":"Search","filterStrictSearch":false},

{"field":"cabinet","checkbox":false,"align":"center","title":"Cabinet","formatter":null,"sortable":true,"filterControl":"input","filterControlPlaceholder":"Search","filterStrictSearch":false},

{"field":"drawer","checkbox":false,"align":"center","title":"Drawer","formatter":null,"sortable":true,"filterControl":"input","filterControlPlaceholder":"Search","filterStrictSearch":false}
]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
djhvscfcommented, Jul 24, 2018

Great! @cgountanis

1reaction
cgountaniscommented, Jul 25, 2018

Confirmed it seems to be accepting the JSON via JS and populating the columns and data properly now.

Primitive example in case someone stumbles on this. Keep in mind the JSON has values needed for the column filter control which you might not need.

$table.bootstrapTable({
    height: getHeight(),
    data: fromAJAXJSON.data,
    columns: fromAJAXJSON.columns
});

In a perfect world you would most likely want to combine the data and columns into one JSON call for timing reasons rootObject.data/rootObject.columns but you get the point. Example data JSON: https://api.myjson.com/bins/r8nya Example columns JSON: https://api.myjson.com/bins/zkqf6

image

Since then though we have decided to use JSON for the DATA in the HTML (data-url) and just dynamically create the THEAD part of the HTML to save some headaches. Using JS just for the client side logic as most of the examples have.

Good fix though for the next release in case someone wants to dynamically specify data and columns via JSON within JS directly though! Thank you…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use column formatting to customize SharePoint
Under Column Settings, choose Format this column. ... To format a column, enter the column formatting JSON in the box.
Read more >
15.10 - Examples: Inserting Values into a JSON Column
Example: INSERT Statement The example creates a table with a JSON column, allocates and initializes a JSON instance using the JSON constructor, then...
Read more >
4 Creating a Table With a JSON Column
You can create a table that has JSON columns. Oracle recommends that you use JSON data type for this.
Read more >
zapier integration salesforce
"it's merely a HTTP POST to the URL of client API, and send JSON ... For example, receiving an email or creating a...
Read more >
Creating columns from JSON - KNIME Analytics Platform
I'm working with a JSON file structured like this: I want to be able to write to a table where the “@k” values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found