Combining the data from 2 columns into one column for display in table?

Combining the data from 2 columns into one column for display in table?

tjyoungtjyoung Posts: 24Questions: 2Answers: 0
edited December 2012 in General
Is it possible using server side processing to combine 2 values (2 different columns) so they are rendered together in one cell in a table? For instance I'm retrieving 'City' and 'State'. In my rendered table I would like to have it show the City and State together instead of having to have 2 separate columns
Hope that makes sense...
tj

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    I'd suggest doing it on the client-side with mRender, particularly if you are using objects in your data source. That way you can do something as simple as:

    [code]
    mData: null,
    mRender: function (data, type, row) {
    return row.City +', '+ row.State;
    }
    [/code]

    Allan
  • radi8radi8 Posts: 31Questions: 6Answers: 0
    edited December 2012
    Assuming dynamic content, this can also be done when building the JSON or when defining the SQL.
    (assuming php)
    [code]
    // sql - using ltrim(rtrim(city)) will remove any whitespace in the data as well
    $sql = "select city + '/' + state as 'city/state'"

    //json
    $arr = array();
    $arr[0] = $city.'/'.$state;
    return json_encode($arr);
    [/code]
    This will concatenate the 2 fields together. Most SQL engines have similar functionality.
This discussion has been closed.