How to add to row id to the join value?

How to add to row id to the join value?

ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

Hello.

In my table i am making a join connection to another table, and i want to show in the table : row_id + join_value.

example: 5 - jon

also

https://editor.datatables.net/examples/simple/join.html -> i want to add the id of the location ("2 - London").

i tried to add getFormatter() to the join command but it didnt work..

Thanks

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    The way I would suggest doing it is have to separate Field::inst() fields in your PHP and then use a client-side renderer to combine the two values into a single column in the table.

    Allan

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

    Hi Allan and thanks for the help.

    I tried to do that using the string formatter method and didn't quite worked.

    Is it even possible to render via that method because it says that i canot get the row data in this method.

    this is how my js data looks like.

    [  
       {  
          "data":"offers_main_table.title",
          "render":"offer_status_at_upload_platforms.offer_id",
          "editField":"offer_status_at_upload_platforms.offer_id"
       }
    ]
    

    every time i add the render i get this error:

    DataTables warning: table id=offer_status_at_upload_platforms - Requested unknown parameter 'offers_main_table.title' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

    basically i want it to show : offer_status_at_upload_platforms.offer_id + offers_main_table.title.

    any thoughts about that?

    thanks !

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Yes, as I say, I would suggest using a client-side render. You need to define a function as detailed in the documentation that will combine the two fields as you need.

    The error you are seeing suggests that there is no offers_main_table.title property in the JSON data returned from the server.

    Allan

    Allan

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

    Thanks Allan

    I cant figure out how to bind those two strings together using the string data only,

    this is the json data that coming back from the server.

    {  
       "data":[  
          {  
             "DT_RowId":"row_1",
             "offer_status_at_upload_platforms":{  
                "offer_id":"1"
             },
             "offers_main_table":{  
                "title":"Jamba - DE - Incent (EUR)_Daft Punk - DE - Incent"
             }
          },
          {  
             "DT_RowId":"row_15",
             "offer_status_at_upload_platforms":{  
                "offer_id":"169"
             },
             "offers_main_table":{  
                "title":"Mozook Android - CR - Incent"
             }
          }
       ],
       "options":{  
          "offer_status_at_upload_platforms.offer_id":[  
             {  
                "label":" Bwin iOS App - FR",
                "value":"1438"
             },
             {  
                "label":" Curious World iPad App - US ",
                "value":"3292"
             }
          ]
       }
    }
    

    I tried every combination possible :neutral:
    but still didnt get it..

    for example

    [ 
       { 
          "data":"offers_main_table.title",
          "render":"offer_status_at_upload_platforms.offer_id",
          "editField":"offer_status_at_upload_platforms.offer_id"
       }
    ]
    

    how can i tell the render to combine those two strings ?

    [ 
       { 
          "data":"offers_main_table.title",
          "render":"offer_status_at_upload_platforms.offer_id[,offers_main_table.title ]",
          "editField":"offer_status_at_upload_platforms.offer_id"
       }
    ]
    

    it seems very strange...

    Thanks :)

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    As I mentioned, you need to use a function:

    render: function ( data, type, row ) {
      return row.offer_status_at_upload_platforms.offer_id +' '+ row.offers_main_table.title;
    }
    

    Allan

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

    Yes but i dont have javascript in my code... ( i wish :) ),

    I configure my table with strings, like it says in here :smile:
    https://datatables.net/manual/data/renderers

    "Strings

    A less common option for formatters is as a string to simply point at the data that should be used in the table. This is similar to the way that columns.data is often used, although keep in mind that the renderer will only have access to the data pointed to by columns.data rather than the full row.

    Continuing the examples using the JSON data structure from above, consider a column that should show the first name of the creator:"

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I'm afraid I don't understand - why can't you use a function? Yes, you can use a string with columns.render, but that only allows you to access a single data point from the source data object. If you want to access more than one, or combine them, you have to use a function.

    Allan

This discussion has been closed.