Yii2 gridview search form filter from another table result - mysql

I want to add a search form on my grid view
In search from, I have dropdown field according to each selection in dropdown I want to filter my gridview.
for example when I select equal in the dropdown and then type 2 in my question amount input, grid view show member that ask two questions.
also, I join three table
in the search model I add:
$query->joinWith(['base_user']);
$query->joinWith(['question']);
and
'question' =>function($r){
if ($this->questionCount == User::ASKED_QUESTION_EQUAL) {
if ($this->questionCount == User::ASKED_QUESTION_EQUAL) {
$rows = (new \yii\db\Query())
->select(`tbl_question`.`create_user_id`)
->from('{{%question}}')
->leftJoin('{{%user}}','{{%question}}.create_user_id = {{%user}}.user_id')
->groupBy(`{{%question}}.create_user_id`)
->having(['create_user_id'=>$this->user_id])
->count();
if ($this->questionAmount = $rows){
$r->andFilterWhere(['=', 'questionAmount', $rows]);
}
}
}
}
but I get
Database Exception error Unknown column 'questionAmount' in 'where clause'
also I add questionAmount on my question model
if I change last code to:
$query->andFilterWhere('LIKE',$this->askedQuestionAmount, $rows);
I get error again
Any help would be greatly appreciated. Thank you!

Related

Sorting on empty kendo grid shows old data

I have a dropdown(having 2 values - Employee and department) and two kendogrids(emp grid and dept grid), on change of dropdown I am enabling/disabling grid based on dropdown value and also clearing datasource of both grid, when I select employee in dropdown and sort employees based on name it gives results, when i change dropdown value to 'Department' it disables employee grid and shows 'No data found' in employee grid,but when I clicked on EmpName column i still got the previous results. I have added dropdown change sample code below.
var ddlvalue = $("#drpmodule").data("kendoDropDownList").text();
$("#EmpGrid").data("kendoGrid").dataSource.data([]); //Clear EmpGrid DataSource
$("#DeptGrid").data("kendoGrid").dataSource.data([]); //Clear DeptGrid DataSource
if (module == 'Employee') {
$('#DeptGrid').addClass('k-state-disabled');
$('#EmpGrid').removeClass('k-state-disabled');
}
else if (module == 'Department') {
$('#EmpGrid').addClass('k-state-disabled'); //shows no data found in EmpGrid, but clicking on column header gives results
$('#DeptGrid').removeClass('k-state-disabled');
} else {
$('#EmpGrid').removeClass('k-state-disabled');
$('#DeptGrid').removeClass('k-state-disabled');
}
I am not getting why Employee grid is showing previous/old data even after 'No data found' records(on changing dropdown).
It would be nice to see how the datasource is configured.
As it is I can assume that maybe when you are filtering, the datasource is fetching data. It would explain why you see data on filtering the empty grid.
Maybe hiding the disabled grid could be a solution : $('#EmpGrid').hide();
Then display it again $('#EmpGrid').show();
By hiding/showing the grid you don't need to empty the grid anymore.

How to check in sikuli that image is exist in screen or not and perform if else condition on that result

I am trying to automate a desktop application in sikuli. What i am doing copying data from from existing user and creating new user using some of that data. In form there are two check boxes. If that check boxes is ticked for existing user, then while creating new user i need to check the text box. for that am taking checked text box image and giving in if condition. If checked text box image is there in that page i will carry value 1 to a variable else value will be 0. according to that value am performing check uncheck function in new user creation page. But the issue what i am facing is, am not able to check if the image exist in that page or not in sikuli. Please anybody help me. my code is giving below
int bomanager=0;
int boswitchboard=0;
System.out.println("boswitchboard value before assign it to 1" + bomanager);
if (screen.exists("images/backofficeswitchboardwithtick.png") != null)
{
boswitchboard=1;
System.out.println("boswitchboard value after assign"+boswitchboard);
}
System.out.println("bomanager value before assign it to 1" + bomanager);
if(screen.exists("images/backofficemanagerwithtick.png") != null)
{
bomanager=1;
System.out.println("bomanager value after assign it to 1"+bomanager);
}
then using this value need to perform below function.
System.out.println("Before condition" + bomanager);
if (bomanager ==0){
screen.click("images/backofficemanagerwithtick.png");
}
screen.setAutoWaitTimeout(10);
System.out.println("Before condition" + boswitchboard);
if(boswitchboard==0){
System.out.println("Inside To tick Condition" + boswitchboard);
System.out.println("Ticking the SwitchBorad when itsnot already ticked");
screen.click("images/backofficeswitchboardwithtick.png");
}
I'm asssuming you're looking to use "if exists" method here
if exists(img, timeout):
click(img)
else:
....
with the method exists() I usually use:
if(exists("yourUrlImage")!=null):
(do something when exists)
else:
(do another thing when not exists)
Because that will return a "match" object.
Hope this helps

Kendo Grid : Hiding a Group Header When value is empty

Is there a way to check that if the group value that is returned is "null" and then hide the group header and expand/collapse button if that is the case?
There is no easy way to go about this. However you can try this in your grid:
dataBound: function (e) {
if ($('#grid').data('kendoGrid').groupable.dataSource._group.length > 0) {
$('#grid tbody .k-grouping-row').filter(function (index) {
return $(this).find("p")[0].innerText.slice(-1) === ":";
}).hide();
$('tr td:empty').parent().hide();
} else {
$('tr td:empty').parent().show();
}
}
Every time you group a column, it calls the dataBound event. First, I check the grid for its grouped columns.
If the grid is being grouped, I find all the group header rows that end in : (meaning that the value being grouped on was empty or null and the label would show Contact Name: for example). I also find all the data rows that have an empty cell, and I hide both the header and data rows.
However, when ungrouping, I have to reveal data rows with null/empty cells again. The header rows are removed automatically. You can check this out in action here --> jsFiddle Demo. Edit the first row's name to be nothing, and then group. It will not show any empty groupings.
This is very hacky and unknown problems could arise, but hope it helps though!

How to remove column number from p:barChart

I am using primefaces p:barChart which is a part of the jqplot api.
I want to remove the column number (the lest number 1 ) from the jqplot-highlighter-tooltip()
I assume the answer is in one of the options in the following
http://www.jqplot.com/docs/files/jqPlotOptions-txt.html but I didn't find the correct one
Can someone can please point me to the relevant attr ?
Thanks
function ext() {
this.cfg.highlighter = {
tooltipAxes: 'y'
};
}

AdvancedDataGrid: dataTip = headerText

I have a pretty straightforward question which google fails to give me the answer to :
I have an AdvancedDataGrid where i build the columns dynamically (variable number of columns) in ActionScript, and i want the dataTip to display the column headerText when the user hovers over a cell. Adobe's example dataTipFunction:
private function tipFunc(value:Object):String
{
if (value is AdvancedDataGridColumn)
return "Column Name";
// Use the 'name' property of the data provider element.
return "Name: " + value["name"];
}
But in this case the value is only an AdvancedDataGrid column if the user hovers over a column header? I want the dataTip to always show the headerText for that column. So if i have to use this function, then how do i get the column headerText for a cell?
And as i understand the dataTipField i can't really use it to statically equal column.headerText (dataTipField = headerText).
Anyone have any pointers on how i can achieve this? It seems like a really easy task, still i can't seem to find out how :)
You can use a different function per column, which could be anonymous:
<AdvancedDataGridColumn dataTipFunction="{function(value:Object):String{return 'Data Tip'}}" ... />