JqWidgets treegrid issues wiring up dataAdapter object - jqwidget

I'm in the AngularJS environment, and trying to get a jqWidgets TreeGrid working.
I have the dataAdapter all wired up with the Json formatted data, however the grid renders only one row.
I also have a test treeGrid on the same page, and with sample data, which is working fine.
I'm putting the final Json data setting side-by-side to try and determine where I'm going wrong.
I've used this page as a guide to wire up the treegrid settings, etc. http://www.jqwidgets.com/jquery-widgets-documentation/documentation/angularjs/angularjs.htm
Here is the html showing the jqx treegrid directive for the "bad" grid:
<jqx-tree-grid jqx-instance="jqGridHierObj" jqx-settings="vm.jqGridHierSettings"></jqx-tree-grid>
And the "bad" Json data tree settings binded vm.jqGridHierSettings (too large to post inline):
http://www.bobmazzo.com/grid/TreeGrid_Data_Bad.txt
and here is the "good" grid with Employee test data :
HTML:
<jqx-tree-grid jqx-instance="jqGridEmpObj" jqx-settings="vm.jqGridEmpSettings"></jqx-grid>
vm.jqGridEmpSettings Json data :
http://www.bobmazzo.com/grid/TreeGrid_Data_Good.txt
and from my Angular controller code, a snippet of the javascript with Json data bindings :
I need help to figure out why the "bad" grid is not working ! And why it only renders one row, where is should be showing a hierarchy of data.
thanks.
Bob

I found the solution. You must define the “children” as an array type in the 'source' object; that is, prior to passing that object into the dataAdapter. See the dataFields property below :
var source = {
dataType: "json",
dataFields: [
{
"name": "id",
"type": "number"
},
{
"name": "field0",
"type": "string"
},
{
"name": "field1",
"type": "number"
},
{
"name": "field2",
"type": "number"
},
{
name: 'children', // MUST DEFINE CHILDREN AS ARRAY TYPE
type: 'array'
},
],
hierarchy: {
root: 'children'
},
id: 'id',
localData: myData
};
var dataAdapter = new $.jqx.dataAdapter(source);

Related

Datatables script DOM

I'm using datatables and I have created this javascript code
table = $('#examples').DataTable({
"ajax": {
type: "POST",
url: "./../../" + "/back-end/switch-ajax-listening/switch-ajax-listening.php",
dataType: "json",
data:
{
actionId: "page1GetAll"
}
},
dom : "B<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>",
"buttons": [
{
extend: 'colvis',
postfixButtons: [ 'colvisRestore' ],
container : '#colvis',
columns: '0,1,2,3,4,5'
}
],
responsive: true,
"columns": [
{ "data": "idSelectPacketName"},
{ "data": "idSelectCompany" },
{"data":null,"defaultContent":"<button>View</button>"}
],
});
It works very well but I cannot be able to understand this part:
"B<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>"
I have not written this string I have copied from an example but I am not able to understand how it works. Or have you known a guide to understand very well this string?
Because my problem is that some times the button is not aligned with the table, have you some ideas in order to solve it? Thanks.
It's a bit flakey as the author admits himself, for now, you need to put the Datatables keyletters in the correct places amongst the html tags. Something like:
dom : "<'row'<'col-sm-6'lB><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>",
(placing the 'B' after the 'l')
You may also have to use CSS to obtain the desired layout.

Rendering same component (with synced data) twice on same page

I've read a lot of documentation but I can't get the following use case to work:
I've got a component 'product-filter'. This component contains the child component 'product-filter-option' which renders a individual filter option (checkbox with label)
The json data for a product-filter instance looks like:
"name": "category",
"title": "Category",
"options": [
{
"value": "value",
"label": "Label 1",
"active": true,
"amount": 8
},
{
"value": "value2",
"label": "Label 2",
"amount": 15
},
etc.
]
I've got multiple instances of product-filter (and a lot of product-filter-option instances) on my page. So far so good.
Now I'd like to render one of my filters (eg. the given Category filter) multiple times on my page (sort of current 'highlighted' filter, which can change during user interaction).
So I've tried to fix this with the following template code:
<filter-component v-if="activefilter"
:name="activefilter.name"
:type="activefilter.type"
:title="activefilter.title"
:tooltip="activefilter.tooltip"
:configuration="activefilter.configuration"
:options="activefilter.options">
</filter-component>
So this filter now shows up 2 times on my page (only when the activefilter property in the vue app is set). But as you might guess when changing an option in this 'cloned' filter the original filter doesn't change, because the data is not synced between these 'clones'.
How can I fix this with Vue?
Thanks for your help!
#roy-j, thanks for your comment about sync. I already tried that by setting:
<filter-component v-if="activefilter"
:name="activefilter.name"
:type="activefilter.type"
:title="activefilter.title"
:tooltip="activefilter.tooltip"
:configuration="activefilter.configuration"
:options.sync="activefilter.options">
</filter-component>
This didn't work. But You got got me thinking, the options sync was not the issue, the sync of the 'checked' state was the issue.
It worked by changing :checked="option.active" to :checked.sync="option.acitve" to the child component: 'filter-option-component'!
Thanks!!

How can I use REST url as data in Vega-lite

I have this REST API that returns tabular data in the following way:
{"data": [{"el1": 8, "el2": 9}, {"el1": 3, "el2": 4}]}
I would like to use el1 and el2 in a Vega-lite chart. How should I refer to the elements in the array?
From the documentation here:
(JSON only) The JSON property containing the desired data. This parameter can be used when the loaded JSON file may have surrounding structure or meta-data. For example
"property": "values.features"
is equivalent to retrieving json.values.features from the loaded JSON object.
It seems that you can try to specify the "property" property (punny, eh) on the format. Something like this:
"data": {
"url": <your url here>,
"format": {
"type": "json",
"property": "data"
},
}
Disclaimer: I haven't actually tested this but it looks to be supported (:

Datatables 1.10 bSelectedOnly equivalent

I'm trying to find the equivalent of bSelectedOnly in the new version of Datatables 1.10.
I only want to print rows that the user has selected, or print all rows if they havn't selected any.
"tableTools": {
"sSwfPath": "/Datatables-1.10.0/extensions/TableTools/swf/copy_csv_xls.swf", //Add buttons for saving table data in these formats
"sRowSelect": "os", //allow user to select multiple rows in the table
"aButtons": [
{
"sExtends": "print",
"bSelectedOnly": "true",
},
{
"sExtends": "select_none",
},
]
},
It hasn't changed (see docs). But you have an error in your code. Instead of
"bSelectedOnly": "true",
it should be
"bSelectedOnly": true,
Also, bSelectedOnly is not available as a print option. It is only available as a flash button option. See here. That is the actual reason why what you're trying to do will not work :)

"No data available in table" in DataTables

I get the message when trying to populate my table. Here's the simplified code.
$("#showUsers").on("click", function() {
$.ajax({
url: "/showUsers",
contentType: "application/json",
processData: false,
complete: function(data) {
$("#output").html(data.responseText);
$("#example").dataTable({
"aaData": data,
"aoColumns": [{
"sTitle": "Name",
"mDataProp": "name",
"sDefaultContent": ""
}, {
"sTitle": "Movie",
"mDataProp": "movie",
"sDefaultContent": ""
}]
});
}
});
});
And
<table id="example">
<thead>
<th>name</th>
<th>movie</th>
</thead>
</table>
The data is assigned valid json:
[{
"name": "Dan",
"movie": "Amelie"
}, {
"name": "Rob",
"movie": "Dungeon"
}]
I've read that sometimes it messes with the table itself and the headers and stuff so I tried removing the <thead> from my table definition but it results with the same issue.
Funny thing is that, if I replace "aaData":data with "aaData": plus the json itself, it works. But I can't make data fill the requirements needed by DT.
The ajax data comes from a node-mysql module which is working properly.
If I change data to data.responseText (this is the json as shown before) I get the warning requested unknown parameter 'name' from the data source for row 0.
I know this should be fairly simple for any not-so experienced DataTables user so thanks in advance. Somehow I'm being unable to sort it out.
SOLVED
The MySQL response comes with a data.responseJSON which is a working format to give to aaData. Thanks.
For the sake of flagging the question as awnsered.
SOLVED.
The mysql response comes with a data.responseJSON which is a working format to give to aaData. Thanks.
Just got wondering why my dataTable was not filling.
In addition to the correct json format needed with aaData, iTotalRecords and iTotalDisplayRecord, aaData needs to be an array (['a', 'b', ...]) and not an object ({'a': 'b', ...}).