DataTables / Editor-PHP

PHP server-side libraries for Editor
Other
35 stars 22 forks source link

Mjoin + SearchPaneOptions #4

Open cgo123 opened 4 years ago

cgo123 commented 4 years ago

Currently, SearchPaneOptions of Fields in Mjoin-Class are ignored.

Would be very helpful if there was a workarround for this.

DataTables commented 4 years ago

Thanks for flagging this up! I can't say when exactly we'll get to this, but it is now on the radar.

cgo123 commented 4 years ago

My Workarround currently is to use a view and concat the 1:x entries:

SQL-Part: GROUP_CONCAT(tbl_contact_types.contact_type_name SEPARATOR ', ') AS contact_type_names ... LEFT JOIN tbl_contact_types ON tbl_contact_types.contact_uuid = tbl_contacts.uuid

PHP Part for Search Pane:

/**
 * Create data for search pane
 */
$contactTypeCounts = $contact->getContactTypeCounts();
foreach ($contactTypeCounts as $contactTypeCount) {
    $resultArray['searchPanes']['options']['contact_type_names'][] = [
        'count' => $contactTypeCount['contact_type_name_count'],
        'total' => $contactTypeCount['contact_type_name_count'],
        'label' => $contactTypeCount['contact_type_name'],
        'value' => $contactTypeCount['contact_type_name']
    ];
}

PHP Processing Search

/**
 * Special cases contact_type_names
 */
$searchedcontactTypeNames = $_POST['searchPanes']['contact_type_names'];
unset($_POST['searchPanes']['contact_type_names']);

for ($i = 0, $ien = count($_POST['columns']); $i < $ien; $i++) {
    $column = $_POST['columns'][$i];
    $search = $column['search']['value'];
        if ($column['name'] == 'contact_type_names') {
            foreach ($searchedcontactTypeNames as $searchedcontactTypeName) {
                $editor->where($editor->_ssp_field($_POST, $i), '%' . $searchedcontactTypeName . '%', 'LIKE');
            }
        }
}

With this workarround you can filter and search contact_type_name