Table not refreshed when WHERE clause is added
Table not refreshed when WHERE clause is added
Hello,
following below patial code code:
// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'addressbook' )
->fields(
Field::inst( 'name' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'company' ),
Field::inst( 'email' )
->validator( 'Validate::email' ),
Field::inst( 'description' ),
Field::inst( 'owner' )
);
if ( isset($_POST['action']) && ( $_POST['action'] === 'create' || $_POST['action'] === 'edit' ) ) {
$_POST['data']['owner'] = strtolower($_SESSION['username']);
}
$editor
// Set WEHRE clause from previously declared variables
->where( $key = "owner" , $value = $sql_value, $op = $sql_op)
->process( $_POST )
->json();
The table does not reload data after new form insert while works well when ->where( $key = "owner" , $value = $sql_value, $op = $sql_op)
is commented out.
Is there any reason for that?
May i need to modify the code on any way?
Thankl you
This discussion has been closed.
Answers
Does the new row meet the criteria for being included in the where condition? Looking at it, it probably does, but just to check if you do a refresh, is the data then shown? What is the server returning from a create action?
Allan
Yes, cause the owner is the same.
and ... when you refresh the table the data is displayed.
and ... the server return {"row":null}
Interesting - I'm back home for the night now, but I'll take a look into try to reproduce this when I get into the office tomorrow.
Thanks,
Allan
Hi,
did you get any chance to verify this behavior?
Thank you
Sorry - absolutely swamped at the moment and haven't had a chance yet. I will as soon as I can and post back here.
Allan
No problem...
Thank you
Hi,
I've just tried this and it appears to work as expected as far as I can tell locally.
You noted that the return is
row: null
when yourwhere
line is commented out. That means that row that was created did not meet the requirement for being included in the output (at least, that is the most likely explanation I think).Try rewriting it as:
I don't really see why you would want to set variables in the function call.
Also is
$sql_value === $_SESSION['username']
? And what is$sql_op
?Allan
Hello,
unfortunately ->where( "owner" , $sql_value, $sql_op) didn't work yet.
The row=null appears only when where clause is added while when are not the row is return correct value and the table is refresh correctly.
So $sql_value === $_SESSION['username'] is needed to retrieve username.
This will query only records created by given username belonging to a specific group.
$sql_op can assume the following value: "=" or "<>" in order to changhe query result based on username.
Hope this clarify the situation.
Hi,
I just experimented with this a little bit earlier on today, and I didn't have any problem using a
where()
statement in the Editor code. I did have an error initially when meant the row wasn't in the result set, which was retiring a row value ofnull
, but with the correct values it seems to work okay as far as I can tell.I'm afraid I would need to be able to recreate the issue to offer much help. Are you able to let me debug it on the server, or can you zip up all of the required files and the database?
Allan
sure....i will prepare all stuff asap.
How cai i send it to you?
allan @ this domain.net :-)
Allan
Maybe i found the problem but i need your support.
when i edit a record one of the filed is not present from editor because is passed
with fnServerParams while drawing Datatables the same record has read from php datatables query.
In my opinion one possible solution should be to hide this filed from editor form and not to remove it.
Could you suggest me a way to do that or a possible workaround?
Would it be appropriate to send the same parameter when making the Editor edit request? You can use
ajax.data
to do that.I'm struggling a little to understand this without being able to see the code I'm afraid. It sounds like the problem is occurring before Editor doesn't know about that field?
Allan
Yes correct...this is the problem...i will send you asap the code
Thank you