Query on multiplegroup - jqgrid complex search - jqgrid

I am using jqgrid with multiplegroup option true for search. My filter looks like the following:
{"groupOp":"OR",
"rules":[{"field":"Total_case","op":"eq","data":"29"}],
"groups":[{"groupOp":"AND",
"rules":[{"field":"Total_case","op":"eq","data":"2"},{"field":"percent","op":"eq","data":"100"}],
"groups":[]}]}
I have rows with both total case = 2 ,percent = 100 and total case = 29. Since outer condition is "OR" condition, I am expecting two rows. However it displays no record. What is wrong?

The question seems be duplicate from answer your previous question. I just wrote the answer on your original question where I confirmed that it's a bug in the current version of jqGrid. As a workaround I suggested to modify requests having "groupOp":"OR" and both non-empty parts rules and groups so that the rules part will be inserted as new additional group inside of groups.
On the example which you posted one can first use jQuery.parseJSON to convert the JSON string postData.filters which you posted to the object form
{
groupOp: "OR",
rules: [
{field: "Total_case", op: "eq", data: "29"}
],
groups: [
{
groupOp: "AND",
rules: [
{field: "Total_case", op: "eq", data: "2"},
{field: "percent", op: "eq", data: "100"}
],
groups: []
}
]
}
Then one could test that groupOp is "OR" and both rules and groups are non-empty arrays. In the case one can move the rules part inside of groups. In other words one could convert it to the following object
{
groupOp: "OR",
rules: [],
groups: [
{
groupOp: "AND",
rules: [
{field: "Total_case", op: "eq", data: "2"},
{field: "percent", op: "eq", data: "100"}
],
groups: []
}
{
groupOp: "AND",
rules: [
{field: "Total_case", op: "eq", data: "29"}
],
groups: []
}
]
}
At the end one can use JSON.stringify to convert the object back to JSON string and assign the results back to postData.filters.
UPDATED: I posted the pull request which describe the changes which will do jqGrid internally during processing of the filtering/searching request.
The demo uses the fix and it seems that all works correctly now.

Related

Kendo-ui grid virtualization of remote data

I have a web service that returns around 100,000 records of data. The returned data is an array of json objects which has the structure as follows:
[
{"name": "Aron", id: 1, type: "R"},
{"name": "Tina", id: 2, type: "R"},
{"name": "Phil", id: 3, type: "R"}
]
I want to use the kendoGrid, and I want to know if using the scrollable: { virtual: true } option is sufficient or should I have to reformat the data.
You dont have to change your data, you just need to initiate an kendoGrid() and in you config put scrollable: { virtual: true } I did an jsfiddle example
Hope this help

Adding additional fields to ElasticSearch terms aggregation

Indexed documents are like:
{
id: 1,
title: 'Blah',
...
platform: {id: 84, url: 'http://facebook.com', title: 'Facebook'}
...
}
What I want is count and output stats-by-platform.
For counting, I can use terms aggregation with platform.id as a field to count:
aggs: {
platforms: {
terms: {field: 'platform.id'}
}
}
This way I receive stats as a multiple buckets looking like {key: 8, doc_count: 162511}, as expected.
Now, can I somehow add to those buckets also platform.name and platform.url (for pretty output of stats)? The best I've came with looks like:
aggs: {
platforms: {
terms: {field: 'platform.id'},
aggs: {
name: {terms: {field: 'platform.name'}},
url: {terms: {field: 'platform.url'}}
}
}
}
Which, in fact, works, and returns pretty complicated structure in each bucket:
{key: 7,
doc_count: 528568,
url:
{doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: [{key: "http://facebook.com", doc_count: 528568}]},
name:
{doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: [{key: "Facebook", doc_count: 528568}]}},
Of course, name and url of platform could be extracted from this structure (like bucket.url.buckets.first.key), but is there more clean and simple way to do the task?
It seems the best way to show intentions is top hits aggregation: "from each aggregated group select only one document", and then extract platform from it:
aggs: {
platforms: {
terms: {field: 'platform.id'},
aggs: {
platform: {top_hits: {size: 1, _source: {include: ['platform']}}}
}
}
This way, each bucked will look like:
{"key": 7,
"doc_count": 529939,
"platform": {
"hits": {
"hits": [{
"_source": {
"platform":
{"id": 7, "name": "Facebook", "url": "http://facebook.com"}
}
}]
}
},
}
Which is kinda too deeep (as usual with ES), but clean: bucket.platform.hits.hits.first._source.platform
If you don't necessarily need to get the value of platform.id, you could get away with a single aggregation instead using a script that concatenates the two fields name and url:
aggs: {
platforms: {
terms: {script: 'doc["platform.name"].value + "," + doc["platform.url"].value'}
}
}

Elasticsearch group by field or missing field

I have a difficulties with elasticsearch.
Here is what I want to do:
Let's say unit of my index looks like this:
{
transacId: "qwerty",
amount: 150,
userId: "adsf",
client: "mobile",
goal: "purchase"
}
I want to build different types of statistics of this data and elasticsearch does it really fast. The problem I have is that in my system user can add new field in transaction on demand. Let's say we have another row in the same index:
{
transacId: "qrerty",
amount: 200,
userId: "adsf",
client: "mobile",
goal: "purchase",
token_1: "game"
}
So now I want to group by token_1.
{
query: {
match: {userId: "asdf"}
},
aggs: {
token_1: {
terms: {field: "token_1"},
aggs: {sumAmt: {sum: {field: "amount"}}}
}
}
}
Problem here that it will aggregate only documents with field token_1. I know there is aggregation missing and I can do something like this:
{
query: {
match: {userId: "asdf"}
},
aggs: {
token_1: {
missing: {field: "token_1"},
aggs: {sumAmt: {sum: {field: "amount"}}}
}
}
}
But in this case it will aggregate only documents without field token_1, what I want is to aggregate both types of documents in on query. I tried do this, but it also didn't work for me:
{
query: {
match: {userId: "asdf"}
},
aggs: {
token_1: {
missing: {field: "token_1"},
aggs: {sumAmt: {sum: {field: "amount"}}}
},
aggs: {
token_1: {
missing: {field: "token_1"},
aggs: {sumAmt: {sum: {field: "amount"}}}
}
}
}
}
I think may be there is something like operator OR in aggregation, but I couldn't find anything. Help me, please.

Kendo MVC Grid - filter empty values

How to implement custom filtering to include/exclude empty values (filtering by one column)?
What you could do is add a new column (boolean) in your model to indicate that another column is empty. And filter on this new column.
All you need is a "not equal" filter on the desired column.
<script>
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
data:[{
field1:"A",
field2:"Z"
}, {
field1:"B",
field2:"Y"
}, {
field1:"C",
field2:""
}, {
field1:"D",
field2:null
}],
filter: { field: "field2", operator: "neq", value: "" }
},
height: 550,
columns: [{
field: "field1",
title: "Field 1"
}, {
field: "field2",
title: "Field 2"
}]
});
});
</script>
http://dojo.telerik.com/Esada
---EDIT---
I did some research and i think ajax sometimes works with mvc ... anyways this is what you would do. I dont implicitly see the documentation for it or the mvc docs but its in the ajax docs
---EDIT---
If you set AutoPostBackOnFilter property of a column to True, the user does not need to press the filter button to initiate filtering. Instead, a postback filter operation occurs when the user types a filter in the filter box and presses [Enter] from the keyboard.
When AutoPostBackOnFilter is True, the column assumes a filter operation of Contains for string types or EqualTo for numeric types.You can change this to another filter function by setting the CurrentFilterFunction property. For example:
// filter out a certain column that is null
<telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
UniqueName="ProductName" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true" />
/*
This is a rundown version of the above code
if you happen to have a grid defined somewhere
else in the code. Basically you would do this
to apply the filter or create multiple to apply
multiple.
*/
$(document).ready(function() {
$("#grid").kendoGrid({
filter: {
ColumnName: "TheColumn",
operator: "neq",
value: ""
}
});
});

Filter jqGrid programmatically on client?

Is there a way to filter the data currently displayed in a jqGrid programmatically (in Javascript, not server-side)? All the search examples seem to depend on using jqGrid's own search UI, which doesn't work for me. For example, I'd like to be able to filter based on user actions elsewhere on a page.
I'm imagining something like
jQuery("#grid_id").filter('CategoryID', selectedCategoryID);
where CategoryID is a column in the grid and selectedCategoryID contains, for example, a value chosen by the user in a select element.
If you want to pre-filter your data first:
$('#myGrid').setGridParam({ data: filtereddataarray }).trigger("reloadGrid");
where filtereddataarray contains only records you want to display for this view
If you want to construct your filter programmatically(I use this method, mostly):
var filters = { "groupOp": "AND", "rules": [{ "field": "id", "op": "eq", "data": "9" }, { "field": "amount", "op": "ge", "data": "10" }, { "field": "name", "op": "cn", "data": "do i"}] };
//To filter:
jqGridFilter(filters , $('#myGrid'));
//To reset:
jqGridFilter(null, $('#myGrid'));
function jqGridFilter(filtersparam, grid) {
grid.setGridParam({
postData: {
filters: filtersparam
},
search: true
});
grid.trigger("reloadGrid");
}
You could pass JSON as the data and use the setGridParam method to reload the data!
I have never tried this and not sure how you would get jqgrid to use your client data rather than hit a URL!
Have you had any luck?

Resources