More efficient and CLEAR way to express

More efficient and CLEAR way to express

menashemenashe Posts: 200Questions: 45Answers: 2

I have the following statement which works:

                low_price_index = packagingTable.columns('lowest-price:name')[0][0] + 1 - (packagingTable.column('manufacturer:name').visible() != true ? 5 : 0);

In short, I am computing the Index of the lowest-price column. I also know that if the manufacturer column is hidden, I have also hidden four other columns, for a total of five.

I use the returned Index to color/highlight the column in the table.

Is there a cleaner way to code this? (Any functions that I may not be aware of that account for hidden columns?)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,872Questions: 1Answers: 10,527 Site admin
    Answer ✓

    That certainly doesn't read easily to me:

    low_price_index = packagingTable.columns('lowest-price:name')[0][0]
      + 1
      - (packagingTable.column('manufacturer:name').visible() != true ? 5 : 0);
    

    Or in pseudo code:

    low_price_index = nameColumnIndex + 1 - (5 OR 0)
    

    That seems, unusual. Can you show me an example of the data in the table (i.e. the JSON or HTML source of the data) and your DataTable initialisation code?

    Also, I'd suggest you use column().index() to get a column index, rather than [0][0] (if indeed that is what is needed).

    Allan

  • menashemenashe Posts: 200Questions: 45Answers: 2

    Hi Allan,

    You are simply amazing!

    By not understanding my question, you still gave me the answer (with the reference to columns.index()!!

    table.column(0).visible(false);
     
    var idx = table.column(1).index('visible');
    

    idx is the number that I am interested in!!

Sign In or Register to comment.