Page 1 of 1

Use Ajax posted value as query criteria

Posted: Tue Nov 14, 2017 1:20 am
by Laim71

Hi,
This is some days I don’t succeed in solving this case.
I want to load a list of goals according to the selected employee.
So this is the code attached to the field where the employee’s name is selected
{ // keys = event types, values = handler functions
"change": function(e) {
var $row = $(this).fields();
var matricule = $row["MatAgent"].value();
console.log(matricule); //post to php code to perform an action
$.post(ew_CurrentPage(), {"myajax": 1, "token": EW_TOKEN, "MatAgent":matricule},
function(result) { // Post back your custom data (with the synchronizer token)
// do something after it has finished
console.log(result);
});
}
}
…And the one with which I want first load in GridAdd, the number of line egals to the number of goals and then load in Row_Rendering, the text of goal.
// List Page Load event
function Page_Load() {
//echo "Page Load";
$this->GridAddRowCount =ew_ExecuteScalar("select count(*) FROM vobjectifsagents WHERE Matricule ='".@$_POST["MatAgent"]."'");
}
Result : My query criteria seems not to be applied. Just the default GridAddRowCount number of rows are loaded.
Any idea?

THANKS in advance


Re: Use Ajax posted value as query criteria in Php

Posted: Tue Nov 14, 2017 3:59 am
by kirondedshem

If am getting you right, if say an employee has 8 questions, you want to load 8 rows in grid add where each of the rows has a single question on it and he probabaly just has to fill in answers.

If so there is a post addressing that
NOTE:ALL you have to do is substude your table structure as well as apply the employee filter for the questions by maybe passing it as a get parameter.
"master/detail add page" on viewtopic.php?f=4&t=40867&
AND
"Automatically fill a detail table in grid add" on viewtopic.php?f=4&t=40961


Re: Use Ajax posted value as query criteria

Posted: Tue Nov 14, 2017 11:12 am
by mobhar

Laim71 wrote:
My query criteria seems not to be applied

Because your post variable "MatAgent" depends on change client's event of employee's name. Since that post variable came from that change event, then you need to check whether the "myajax" returns 1 each time "Page_Load" server event is called.


Re: Use Ajax posted value as query criteria

Posted: Tue Nov 14, 2017 8:15 pm
by Laim71

Well, I used the filter option and it works.
But the user must select one by one goals for each line, one's the employee goals are filtered..

Then I find helpful for him if the grid is auto-filled.

I've yet used successfully grid auto-fill script.

So before finding the solution to do so, is it possible to combine the filter solution with the auto-filling script?

THANKS,


Re: Use Ajax posted value as query criteria

Posted: Tue Nov 14, 2017 10:25 pm
by kirondedshem

is it possible to combine the filter solution with the auto-filling script?
Yes they can both be done, but if you are using grid auto fill done from server side then you must also do the filter on server side as well as you need to filter before autofilling.

I've yet used successfully grid auto-fill script.
If grid auto fill is very important to you. Which I feel is coz, you don't want a user to pick one question at a time but rather to go to the form and find all his questions already selected for him.
Then I suggest you first work on it first, coz adding the filter to the code that does grid auto fill is easy as it is just putting a where caluse on the sql statement that picks the questions or goals for that employee. You just have to pass that employee id in parameter and use that to filter out what questions to load onto his form from the server side.