Okay
  Public Ticket #3534479
custom columns
Closed

Comments

  • Daniele started the conversation

    I am using wpDatatables to build views from sql db tables. That's working fine. 

    Now, for each retrieved row, I need also, to add 2 custom columns: the first with the URL links  and the second with a button pointing to a wp page. While is possible to do with standard wpdatatables it seems that such feature is not available for data tables using sql.  Is this true or i miss something? Can you please advices if there is a way to achieve so?

    Thanks a lot.

    P.S. I am novice to wpdatatables

  •  1,708
    Miloš replied

    Hi Daniele,

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    I am not sure if i fully understood your use-case.

    It seems that you made an SQL VIEW in your Database and are calling the data from your VIEW in our SQL Query-based Table, and you succeeded in returning the data you need.

    -

    So now you wish to add two Custom Columns to an SQL Query-based Table?

    Adding or removing Columns directly through our Plugin is only possible with our Manual Tables.


    When you make a Manual Table, this creates a new stand-alone SQL Table in your Database, and you can add/remove Columns through our Plugin directly.

    ( You can also later call this same data through another SQL Table like, check under Editing Tab what's the MySQL Table name, and in a new SQL table just call it as : SELECT * FROM TableName)


    But when you do an SQL Query based Table - this only 'pulls'/calls the existing data from your existing SQL Tables - it does not create a new Table in your Database, if that makes sense.


    But it depends exactly what you mean by adding Custom Columns.


    For example, you can try our new feature "Transform Value".

    You can use this feature if you have some Columns which contain 'part of the value' you need for your URL link, and combine actual values from multiple Columns of your Data in the same cell.



    Here is a basic example we made with a Manual Table.

    A Table with some Products, the Product ID Column named  as "id"  along with Field "ProductName", etc;

    For each Product, we made an individual Page, with URL as  :

    http://myWebsite/page-Product ID/

    For Product ID 221 the full URL will be like :

    http://localhost/current/page-221/

    4873800829.png

    For a Custom Link, i will create a new Column, we will combine manually adding an "a href" HTML hyperlink and add a "target blank" attribute to open it in a new tab, as well as displayed link text.


    For the URL, we added a blank String Column in this Table, and we will  construct it with "Transform Value" Feature.

    We create each cell to start with "<a href="http://localhost/current/page-"  then add the value for the Product ID as column placeholder {id.value} and for the displayed link text we will combine adding the product name such as "Click here to view {productname.value} Page" , ending it with the closing </a> tag, like :

    <a href="http://localhost/current/page-{id.value}" target="_blank">Click here to view {productname.value} Page</a>
    4092167752.png

    Of course, we can additionally add a CSS class to the HTML anchor Tag, such as :

    <a class="customlink" href="http://localhost/current/page-{id.value}" target="_blank">Click here to view {productname.value} Page</a>
    

    Then we can call that class for custom styling and make the link look as a button in the Table's Customize/Custom CSS, and so on.

    9771482354.png

    So, as long as we include some existing column placeholders with values, we can construct custom links, etc.

    We will do our best to add more detailed examples to our Documentation and perhaps some new videos in general that can clarify the possibilities.

    You can additionally check out more details explained how the "Transform Value" feature works on this Page ( if you haven't already).



    2. Another way how you can make Custom Links with SQL Query based Tables is to use the SQL CONCAT function.

    Please check our Video here where we show an example of that.


    Let me know if one of these two methods achieves what you need, or if you need something different?smile.png

    Thank you.



    Kind Regards, 

    Miloš Jovanović
    [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