Okay
  Public Ticket #2078671
Change column value on value of other column
Closed

Comments

  • Jamie Warnock started the conversation

    Hello,

    Firstly, amazing plugin loving it!

    I wish to be able to change the value of a column based on the state of another, for instance:

    If COLUMN A is set to VALUE X then set COLUMN B to VALUE Y

    I thought I could do it using the 'wpdatatables_filter_column_before_save' filter but this does not seem to be fired when editing on the frontend?

    Can you help please?

    regards,
    Jamie



  •  2,496
    Aleksandar replied

    Hello Jamie.

    Unfortunately, conditional formatting between columns is not yet possible with the plugin's built in features.

    We've never done a customization like this, so I would also have to explore the hooks and ways to do this. Maybe wpdatatables_after_frontent_edit_row( $formdata, $rowId, $tableId ) can help. This action is executed after editing action is applied.

    Please note that using hooks requires certain level of programming skills and included support refers only to advice.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Jamie Warnock replied

    wpdatatables_after_frontent_edit_row - worked beautifully!

    I debugged it by firing:

    wp_die( '<pre>' . var_export( $formdata, true ) . '</pre>');

    in the action function so I can see the data in the AJAX response in the console.

    Many thanks.

  • Jamie Warnock replied

    And if any other developer wants to do something similar here is my code:

    add_action( 'wpdatatables_after_frontent_edit_row', 'my_wpdatatables_after_frontent_edit_row', 15, 3 );
    function my_wpdatatables_after_frontent_edit_row( $formdata, $rowId, $tableId ) {
        global $wpdb;
        $table = 'wp_wpdatatable_referrals';
        $outcomes = array(
            'No Contact'                    => 'Open',
            'Prices Given - Verbally'       => 'Open',
            'Prices Given - Email Sent'     => 'Open',
            'CB Scheduled'                  => 'Open',
            'Future Sky Lead'               => 'Open',
            'Not Interested'                => 'Closed',
            'Already a Customer'            => 'Closed',
            'Calling Directly'              => 'Closed',
            'Wrong Number'                  => 'Closed',
            'Customer to Callback'          => 'Closed',
            '4 Attempts MAX'                => 'Closed',
            'Sky Lead'                      => 'Closed',
            'Virgin Sale'                   => 'Closed',
            'Duplicate'                     => 'Closed',
            'Already Signed Up < Month'     => 'Closed',
            'Expired Lead'                  => 'Closed'
        );
        $outcome = $formdata['outcome'];
        if ( $outcome && array_key_exists( $outcome, $outcomes ) ) {
            $status = $outcomes[$outcome];
            if ( $formdata['status'] != $status ) {
                $wpdb->update( $table, array(
                    'status' => $status
                ), array(
                    'wdt_ID' => $rowId
                ) );
            }
        }
        // DEBUG
        // wp_die( '<pre>' . var_export( $formdata, true ) . '</pre>' );
    }
    


  •  2,496
    Aleksandar replied

    Hey Jamie, great work!

    You're welcome.

    Thanks for sharing this, I'm sure someone will have much use of it.

    If you have any other questions or issues, please feel free to open a new ticket, and we'll gladly help.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables