such as I have some array data like this:
{"aaData": [
[
"Trident",
"Internet Explorer 4.0",
"Win 95+",
"4",
"X"
]
]}
but I don't want it show as this order: "Trident", "Internet Explorer 4.0","Win 95+","4","X".
if I wan "Win 95+" at the first column and I don't want to change the source data order. waht can I config in aoColumns option?
You cas use "mData" property like this:
"aoColumns": [
{"mData": 2 },
{"mData": 0 },
{"mData": 1 },
{"mData": 3 },
{"mData": 4 },
]
Integer of "mData" treated as an array index for the data source.
Here http://www.datatables.net/usage/columns you can read more about it.
Related
I am using the url below to fetch the products in a particular category and it works fine.
/rest/default/V1/products?searchCriteria[filterGroups][0][filters][0][field]=category_id&searchCriteria[filterGroups][0][filters][0][value]=262&searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][1][filters][0][field]=visibility&searchCriteria[filterGroups][1][filters][0][value]=4&searchCriteria[filterGroups][1][filters][0][conditionType]=eq&searchCriteria[pageSize]=10&searchCriteria[currentPage]=0
The only issue is that I would like to show filters based on the categories selected. For eg a price filter works for every category but a size and color filter would only work for clothing category while screen size would work for electronics.
Any idea on how to fetch the filters for each category?
I found the answer ,but I had to switch from using rest api to graphql as graphql supports aggregations . This was exactly what I needed and also seems like graphql has more features as compared to rest api for magento 2.
You can try magento search api to get filters by passing category or any other field like below example.
{{url}}/rest/V1/search?searchCriteria[requestName]=catalog_view_container&searchCriteria[filterGroups][0][filters][0][field]=category_ids&searchCriteria[filterGroups][0][filters][0][value]=10
Result will have category and other buckets, something like below:
[
{
"name": "category_bucket",
"values": [
{
"value": "2",
"metrics": [
2,
634
]
},
{
"value": "10",
"metrics": [
10,
634
]
}
]
},
{
"name": "brand_bucket",
"values": [
{
"value": "617",
"metrics": [
617,
562
]
},
{
"value": "639",
"metrics": [
639,
29
]
},
{
"value": "1218",
"metrics": [
1218,
26
]
},
{
"value": "640",
"metrics": [
640,
8
]
},
{
"value": "1332",
"metrics": [
1332,
4
]
}
]
}
]
You can map this result with attribute api result to get label
{{url}}/rest/all/V1/products/attributes?searchCriteria=&fields=items[attribute_id,attribute_code,options,frontend_labels]
I recently took over the development of a website that uses datatables. The site is built using Laravel 4.
I am new to datatables. I was wanting to know if it were possible to have the datatable load but not display any output/rows. The information would only show up once the user fills out the search bar.
I have gone over some of the available documentation on the datatables.net but haven’t found what I am looking for.
EDIT:
Here is a code snippet:
table.dataTable({
// Internationalisation. For more info refer to http://datatables.net/manual/i18n
"language": {
"aria": {
"sortAscending": ": activate to sort column ascending",
"sortDescending": ": activate to sort column descending"
},
"emptyTable": "No data available in table",
"info": "Showing1 _START_ to _END_ of _TOTAL_ entries1",
"infoEmpty": "No entries found",
"infoFiltered": "(filtered1 from _MAX_ total entries)",
"lengthMenu": "Show _MENU_ entries",
"search": "Search:",
"zeroRecords": "No matching records found"
},
// "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
"columns": [{
"orderable": true
},{
"orderable": true
},{
"orderable": true
}, {
"orderable": false
}],
"lengthMenu": [
[5, 10, 20, 100, -1],
[5, 10, 20, 100, "All"] // change per page values here
],
// set the initial value
"pageLength": 10,
"pagingType": "bootstrap_full_number",
"language": {
"search": "Search Patient: ",
"lengthMenu": " _MENU_ records",
"paginate": {
"previous":"Prev",
"next": "Next",
"last": "Last",
"first": "First"
}
},
"columnDefs": [{ // set default column settings
'orderable': false,
'targets': [0]
}, {
"searchable": false,
"targets": [1]
}, { // set default column settings
'orderable': false,
"bVisible": false,
'targets': [4]
}],
"order": [
[4, "asc"]
] // set 5th column as a default sort by asc
});
Take a look at the Server-side processing example.
Let Laravel return an empty array by default so the table data is empty. It will call the ajax script on every "change" so once a user searches for anything, you can return the queried data.
More examples and docs can be found here: https://datatables.net/examples/server_side/index.html
If you're using a package, you should also check the documentation for that version.
I have following query which returns the number of request for each status -
r.db.table("request").group("status").count()
result -
[
{
"group": "ACCEPTED",
"reduction": 1
},
{
"group": "DECLINED",
"reduction": 1
},
{
"group": "PENDING",
"reduction": 1
}
]
How can I convert this result to the following using rethinkdb query (javascript)?
{
"ACCEPTED": 1,
"DECLINED": 1,
"PENDING": 1
}
Currently, I am achieving this by iterating the result in api side. But I want this transformation in rethinkdb, if its at all possible?
r.db("test").table("request").group("status").count()
.ungroup()
.map(function(x){ return [x('group'), x('reduction')]; })
.coerceTo("object")
When you want to continue working on your return object you need to
call the ungroup() function first
Then you need to use the map
function to transform your result to:
[ [ "ACCEPTED" , 1 ] , [ "DECLINED" , 1 ] , [ "PENDING" , 1 ] ]
at last you simply transform this to a json-object with coerceTo("object"), which returns you the desired format:
{
"ACCEPTED": 1,
"DECLINED": 1,
"PENDING": 1
}
I have a query that uses group() function:
...group('a','b','c','na').count()
the now the result is returns like in the form of group and reduction like this:
How can I get result without group and reduce in the form of
{
"na": 1285
"c" : 487
"b" : 746
"a" : 32
}
I'm not sure, but I think you're misunderstanding what group does.
The group command takes a property and groups documents by that property. So, for example, if you wanted to group documents by the a property, that would look something like this:
{
a: 1
}, {
a: 1
}, {
a: 1
}, {
a: 2
}
Then you would run the following query:
r.table(...).group('a').count().ungroup()
Which would result in:
[
{
"group": 1 ,
"reduction": 3
},
{
"group": 2 ,
"reduction": 1
}
]
By passing multiple arguments to group you are telling it to make distinct groups for all those properties. So you you have the following documents:
[ {
a: 1, b: 1
}, {
a: 1, b: 1
}, {
a: 1, b: 2
}, {
a: 2, b: 1
}]
And you group them by a and b:
r.table(...).group('a', 'b').count().ungroup()
You will get the following result:
[{
"group": [ 1 , 1 ] ,
"reduction": 2
},
{
"group": [ 1 , 2 ] ,
"reduction": 1
},
{
"group": [ 2 , 1 ] ,
"reduction": 1
}]
Your Answer
So, when you do .group('a','b','c','na').count(), you're grouping them by those 4 properties. If you want the following result:
{
"na": 1285
"c" : 487
"b" : 746
"a" : 32
}
Then your documents should look something like this:
[{
property: 'a'
}, {
property: 'c'
}, {
property: 'na'
},
...
]
And then you would group them in the following way:
r.table(...).group('property').count().ungroup()
I am working with Coldfusion and jqgrid.
Is there a way to populate the colModel editoptions dynamically from query results?
If you need to set dynamically the options like 1:female;2:male, then I suppose that you fill grid with data which contains 1 or 2 in the specified column. So you have to use formatter: "select" (see the documentation). Thus you should be able to set the properties like below
{name: "sex", formatter: "select", editoptions: { value: "1:female;2:male" }}
If you need to set such options dynamically, that you want to load the information about editoptions.value from the server.
The most native callback which you can use for it is beforeProcessing. The callback will be processed before the data returned from the server will be displayed using the formatter. So one can make any changes of formatoptions or editoptions.
If the server response looks now like
{
"rows": [
{"id": 123, "name": "John", "sex": "2"},
{"id": 456, "name": "Mary", "sex": "1"}
]
}
then you can extend the data of the server response to the following
{
"rows": [
{"id": 123, "name": "John", "sex": "2"},
{"id": 456, "name": "Mary", "sex": "1"}
],
"colModelExtentions": {
"sex": {"formatter": "select", "editoptions": {"value": "1:female;2:male"}}
}
}
In the way you specify some changes of specific items of the colModel directly inside of the server response. The implementation of the beforeProcessing callback which process such data can looks like
beforeProcessing: function (data) {
var cmName, cmExt = data.colModelExtentions, $self = $(this),
p = $self.jqGrid("getGridParam");
for (cmName in cmExt) {
// enumerate properties of colModelExtentions like sex
if (cmExt.hasOwnProperties(cmName)) {
$self.jqGrid("setColProp", cmName, cmExt[cmName]);
}
}
}
and to define the "sex" columns in colModel like
{name: "sex", width: 50}
You will find more details about the scenario in the answer and this one. You can extend the information which return the server. In the case you can need to call setColWidth or setLabel additionally to apply dynamically the column width and the text of the column header.