Calculated Column

Calculated Column

shannonwregeshannonwrege Posts: 22Questions: 9Answers: 0

Can you define a column which is calculated by other columns and not actually in the data set? For example, if you have a column that lists Wins (e.g. "12") and a column that lists Losses (e.g. "4"), can you have a calculated column to show in a responsive table that drops the Wins and Losses column and adds a calculated Record column (e.g. "12-4")?

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    Absolutely. There are a number of ways you can handle this.

    First, how are you adding data to the table? Array of string? object? Already defined HTML table?

    The answer to this question will help me provide you with the correct answer.

  • shannonwregeshannonwrege Posts: 22Questions: 9Answers: 0

    The data is packed in an array. The actual field values are integers, but they could be strings if it makes a difference.

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    So assuming your data is array of objects, I would define columns as following

    {
       "responsivePriority": 2,
       "data": 'wins'
    },
    {
       "responsivePriority": 2,
       "data": 'losses'
    },
    {
       "responsivePriority": 1,
       "data": null,    // this will allow usage of full object
       "render": function ( data, type, full, meta ) {
          return (data.wins + '-' data.losses);
        }
    }
    

    If you don't want to show this combined column all the time, or only on specific resolutions, then utilize responsive classes.

    Also, you will probably need a custom sort function for this combined column.

  • shannonwregeshannonwrege Posts: 22Questions: 9Answers: 0

    That did it. Thanks!

This discussion has been closed.