Okay
  Public Ticket #1722176
Issue with foreign key table
Closed

Comments

  •  1
    Thepaky91 started the conversation

    Hi guys,

    I have a problem with foreign key. 

    I created 3 tables:

    1) food database (composed in food id, food name, kcal, carbo, protein, fats....)

    2) Diet scheme (composed in food database id and grams)

    3) Relational tables that shows all values where food database id (point 2) = food id (point 1)

    In table 3), I set:

    - foreign key to show food name where there is food database id (attachment 1)

    - Set select box in editing section (attachment 2) to choose foods from table 1) to be added in table 3) when I click on "new" button (attachment 3).

    So far, everything works good. 

    The problem is that the table 1) contains the data of 5000 foods. So when I try to add a new row choosing a food in the select box of table 3):

    - it is very slow because it opens a list of 5000 foods ordered from A to Z (attachment 3)

    - there isn't a search box to find a food in this huge list 

    How can I make it fastly and add a search box in the front-end editing to easly find a food?

  •  472
    Isidora replied

    Hi Thepaky91,
    Thank you for your purchase.

    Sorry for late response. 

    We are located in Serbia and our working time is from 10:00 to 17:00 CET. business days.

    You can add search field for foreign keys by changing some code in plugin.

    When you have set column string you have option Number of possible values for load on DATA tab in column settings which is set by default on 10. In this case you will have search field in selectbox, but if you set this option to All,  search field will be removed because all possible values for column will be loaded. For foreign keys from version 2.2.3 this option is removed and by default is set to All.

    If you want to use it on when Number of possible values for load is set to all, you have to make some comments in code.  In file wp-content/plugins/wpdatatables/assets/js/wpdatatables/wdt.columnFilter.js around line 753 you will find this:

    jQuery('.bs-searchbox').hide();

    and you have to comment it like this:

    //jQuery('.bs-searchbox').hide();

    Like this you will have search field for foreign keys in selectbox filter. 

    Code that I provide to you is for filtering. If you need it in edit modal then you have to change code in file

    wp-content/plugins/wpdatatables/templates/frontend/edit_dialog.inc.php around line 71you will find

    <?php if ($dataColumn->getPossibleValuesAjax() !== -1) { ?>data-live-search="true" data-live-search-placeholder="Search..."<?php } ?>


    and you have to replace it with this

    data-live-search="true" data-live-search-placeholder="Search..."

    You have to do one more thing to turn off option Use minified wpDataTables Javascript on CUSTOM JS and CSS tab in settings of plugin, because on front end are used minified files and you were changing original files in core. Like this when you turn it off will be included original files and selecbox in edit modal will work on front.


    Please note that will be overwritten in next update so you have to do it again.

    Performanse of the loading table and serverside process like filtering and sorting depends from few factors. If you are using complicated queries that are not optimize can produce slow filtering and sorting. Also serverside procesing depends of server configuration (php version, mysql...)

    Best regards.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables