Table not refreshed when WHERE clause is added

Table not refreshed when WHERE clause is added

rainolfrainolf Posts: 56Questions: 6Answers: 0
edited May 2014 in Editor

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

Answers

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    Yes, cause the owner is the same.
    and ... when you refresh the table the data is displayed.
    and ... the server return {"row":null}

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    Hi,
    did you get any chance to verify this behavior?

    Thank you

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    No problem...

    Thank you

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    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 your where 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).

    ->where( $key = "owner" , $value = $sql_value, $op = $sql_op)

    Try rewriting it as:

    ->where( "owner" , $sql_value, $sql_op)
    

    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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    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.

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    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 of null, 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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    sure....i will prepare all stuff asap.

    How cai i send it to you?

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    allan @ this domain.net :-)

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    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?

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    Would it be appropriate to send the same parameter when making the Editor edit request? You can use ajax.data to do that.

    In my opinion one possible solution should be to hide this filed from editor form

    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

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    Yes correct...this is the problem...i will send you asap the code

    Thank you

This discussion has been closed.