Short
Can I pass additional data through JSON objects to Datatables which won't be rendered by Datatables?
Longer description
I'm having issues with Internet Explorer (sigh) rendering Datatables in a frustratingly slow manor. Having scoured the web for solutions the best bet I've figured is that I should transfer the creation of the table from HTML to JSON.
Our HTML rows currently look like this:
<tr their_ID="{$data[$i]['their_ID']}" class="$no_select $exists">
<td>$ii.</td>
<td surname>{$data[$i]['surname']}</td>
<td forename>{$data[$i]['forename']}</td>
<td title>{$data[$i]['title']}</td>
<td gender>{$data[$i]['gender']}</td>
<td email>{$data[$i]['email']}</td>
<td import class="centerText"><input type="checkbox" $checked ourID="$ourID" /></td>
</tr>
The JSON seems great if all you are passing is raw data. But for the rest of the functionality to work we need all the additional data for each row and table cell to be passed.
If I have the following:
{
"DT_RowId": "1234",
"ii": "$ii",
"surname": "Surname",
"forename": "Forename",
"title": "Title",
"gender": "M",
"email": "abc#xyz.com",
"import": "$ourID"
},
Using the createdRow callback I can set most of the row and cell data using JS. The ID could be taken and renamed to the custom attribute their_ID. The keynames could be used to add the custom attributes to the cells. I could convert the import cell into a checkbox using JS etc. Determining whether the row could be selected or not ($no_select) could also be done with JS.
The problem we're left with is:
How do we pass the server side determined data of whether the user exists in our database or not?
Is it possible to pass additional data through the JSON which won't be rendered by the Datatables but will be available for us to use? $exists and $checked (which really could be a single variable as far as the JS is concerned)
E.g. theoretically:
{
"DT_RowId": "1234",
"ii": "$ii",
"surname": "Surname",
"forename": "Forename",
"title": "Title",
"gender": "M",
"email": "abc#xyz.com",
"import": $ourID,
"hiddenClientSideData": {
"exists": 1|0,
"checked": 1|0
}
},
Thanks for any help, and if you need any clarifications please ask.
You should be able to use the ColumnDefs and set the visible property to false. Create a column for that data. And then target that column and make it invisible
https://datatables.net/reference/option/columnDefs
You would create two additional th and two addadditional td cells in your table definition. Then just send the data as you are with other properties. To begin with render it on the UI to make sure it is all sending correctly. Then use the columnDefs to target and hide those last two columns. You will still be able to use datatables api to get the data to act on it if needed
Related
I'm very new at Vue.js and i'm trying to access a data from an api. I got some JSON data and i want to access my sensors id's. But sensor id's doesn't have any name. For example, this is my data:
{
"SID":"valid"
}{
"alarms":1598532382,
"chanscan":1,
"cloud_config":1579015363,
"cloud_credentials":1,
"cloud_status":1,
"currData":1598532382,
"favourites":1579015363,
"hardware":1597737383,
"oldestRecords":1,
"scanreq":1,
"sensors_raw":1598270610,
"settings_raw":1597740959,
"users":1597740912
}1598532408{
"1053397":{
"time":1598531818,
"t":30.15,
"h":42,
"lost":0,
"rssi":-67,
"volt":1.48,
"ptype":6,
"grey":0,
"vari":9
},
"3146177":{
"time":1598532123,
"t":30.15,
"h":43,
"p":100070,
"co2":609,
"co2Abc":0,
"lost":0,
"rssi":-58,
"volt":1.56,
"ptype":13,
"grey":0,
"vari":16
},
"4195593":{
"time":1598107788,
"C":103,
"lost":0,
"rssi":-71,
"volt":3.06,
"ptype":13,
"vari":2,
"t":null,
"h":null,
"p":null,
"co2":null,
"co2Abc":null
},
"6292226":{
"time":1598532029,
"t":25.7,
"bec":0.0247,
"pec":0.961,
"dp":5.555887,
"vwc":0.093,
"lost":0,
"rssi":-62,
"volt":1.44,
"ptype":20,
"grey":0,
"vari":1
},
"lastRx":1598532123,
"missing":1,
"paired":4
}{
"1053397":{
"humi":{
"type":"humi",
"since":1598346415,
"desc":"threshumiover",
"value":42,
"diff":12
}
},
"4195593":{
"rssi":{
"type":"fatal",
"desc":"packetslost",
"since":1598107786
}
}
}
What can I do to access the "1598532408", "3146177" and "1053397" values so I can display them in the left column of a table? Example of my vue.js table:
<tr v-for="sensor in list" v-bind:key="sensor">
<td>{{sensor}}</td>
<td>{{sensor.time}}</td>
</tr>
Using {{sensor}} gives me all of my data.
Any help would be tremendously appreciated here. I'll have to redo some of this once they actually get the data right, but for now, this is sort of what I'm working with.
I'll be getting json dynamically from service as follows:
{"items":[[{"key": "SerialID","value": "P1.M1.T1"},{ "key": "Description", "value": "Dummy Desc 1"},{ "key": "Label", "value": "A123"}],[{"key": "SerialID","value": "P1.M1.T2"},{ "key": "Description", "value": "Dummy Desc 2"},{ "key": "Label", "value": "B123"}]]}
Here, sample 2 rows in items array are given. I would get multiple such rows. Also, columns in every row may very (e.g.: Here, I am receiving 3 columns per row. I might receive n number. However, it'll be same for all rows in input).
I want to pass this json as a data source to primeNG table and render it in tabular format. So both, columns and rows, need to be generated dynamically. I tried parsing the json but somehow not able to form appropriate inputs for primeNG table.
Any help is highly appreciated.
I finally iterated my JSON, formed column and row arrays in the format which PrimeNG expects and passed it to component. It worked!
I'm using Google App Script to migrate data through BigQuery and I've run into an issue because the SQL I'm using to perform a WRITE_TRUNCATE load is causing the destination table to be recreated with column modes of NULLABLE rather than their previous mode of REQUIRED.
Attempting to change the modes to REQUIRED after the data is loaded using a metadata patch causes an error even though the columns don't contain any null values.
I considered working around the issue by dropping the table and recreating it again with the same REQUIRED modes, then loading the data using WRITE_APPEND instead of WRITE_TRUNCATE. But this isn't possible because a user wants to have the same source and destination table in their SQL.
Does anyone know if it's possible to define a BigQuery.Jobs.insert request that includes the output schema information/metadata?
If it's not possible the only alternative I can see is to use my original work around of a WRITE_APPEND but add a temporary table into the process, to allow for the destination table appearing in the source SQL. But if this can be avoid that would be nice.
Additional Information:
I did experiment with different ways of setting the schema information but when they didn't return an error message the schema seemed to get ignored.
I.e. this is the json I'm passing into BigQuery.Jobs.insert
jsnConfig =
{
"configuration":
{
"query":
{
"destinationTable":
{
"projectId":"my-project",
"datasetId":"sandbox_dataset",
"tableId":"hello_world"
},
"writeDisposition":"WRITE_TRUNCATE",
"useLegacySql":false,
"query":"SELECT COL_A, COL_B, '1' AS COL_C, COL_TIMESTAMP, COL_REQUIRED FROM `my-project.sandbox_dataset.hello_world_2` ",
"allowLargeResults":true,
"schema":
{
"fields":
[
{
"description":"Desc of Column A",
"type":"STRING",
"mode":"NULLABLE",
"name":"COL_A"
},
{
"description":"Desc of Column B",
"type":"STRING",
"mode":"REQUIRED",
"name":"COL_B"
},
{
"description":"Desc of Column C",
"type":"STRING",
"mode":"REPEATED",
"name":"COL_C"
},
{
"description":"Desc of Column Timestamp",
"type":"INTEGER",
"mode":"NULLABLE",
"name":"COL_TIMESTAMP"
},
{
"description":"Desc of Column Required",
"type":"STRING",
"mode":"REQUIRED",
"name":"COL_REQUIRED"
}
]
}
}
}
}
var job = BigQuery.Jobs.insert(jsnConfig, "my-project");
The result is that the new or existing hello_world table is truncated and loaded with the data specified in the query (so part of the json package is being read), but the column descriptions and modes aren't added as defined in the schema section. They're just blank and NULLABLE in the table.
More
When I tested the REST request above using Googles API page for BigQuery.Jobs.Insert it highlighted the "schema" property in the request as invalid. I think it appears the schema can be defined if you're loading the data from a file, i.e. BigQuery.Jobs.Load but it doesn't seem to support that functionality if you're putting the data in using an SQL source.
See the documentation here: https://cloud.google.com/bigquery/docs/schemas#specify-schema-manual-python
You can pass a schema object with your load job, meaning you can set fields to mode=REQUIRED
this is the command you should use:
bq --location=[LOCATION] load --source_format=[FORMAT] [PROJECT_ID]:[DATASET].[TABLE] [PATH_TO_DATA_FILE] [PATH_TO_SCHEMA_FILE]
as #Roy answered, this is done via load only. Can you output the logs of this command?
Working with the repeating grids through the form builder.
I have a custom control that has a string value represented in json.
{
"data": {
"type": "File",
"itemID": "12345",
"name": "Annual Summary",
"parentFolderID": "fileID",
"owner": "Owner",
"lastModifiedDate": "2016-10-17 22:48:05Z"
}
}
In the controls outside of the repeating grid, i need to check if name = "Annual Summary"
Previously, i had a drop down control and using Calculated Value $dropdownControl = "Annual Summary" it was able to return true if any of the repeated rows contained the value. My understanding is that using the = operator, it will validate against all rows.
Now with the json output of the control, I am attempting to use
contains($jsonStringValue, 'Annual Summary')
However, this only works with one entry and will be null if there are multiple rows.
2 questions:
How would validate whether "Annual Summary" (or any other text) is present within any of the repeated rows?
Is there any way to navigate the json or parse it to XML and navigate it?
Constraint:
within the Calculated Value or Visibility fields within form builder
manipulating the source that is generated by the form builder
You probably want to parse the JSON string first. See also this other Stackoverflow question.
Until Orbeon Forms 2016.3 is released, you would write:
(
for $v in $jsonStringValue
return converter:jsonStringToXml($v)
)//name = 'Annual Summary'
With the above, you also need to scope the namespace:
xmlns:converter="org.orbeon.oxf.json.Converter"
Once Orbeon Forms 2016.3 is released you can switch to:
$jsonStringValue/xxf:json-to-xml()//name = 'Annual Summary'
I have a Json for vendor:
{
"id": 1,
"contact": {
"address": "abc",
"phone": "123456"
}
}
If the update is {"contact": {"address":"xyz"}}, the address should be updated to xyz, and phone is still there, i.e. not deleted.
I know $set and dot notation (https://docs.mongodb.org/manual/reference/operator/update/set/), for example, {$set: {"contact.address":"xyz"}}, can do this.
However, what I am trying to do is to come out with a generic solution in the sense that it can be applied to models with nested depth larger than 2. In other words, given the update in json form, the solution should ONLY update the fields specified in the update and leave other fields intact.