Formatting row from nth cell.

(15 posts) (2 voices)

Tags:

No tags yet.

  1. SBurke, Member

    New to mydbr but not to t/SQL.

    Currently we have a report that changes the format of a row to a different FG/BG colour if a cell is a specific value. However we are using dbr.hdr on the first three columns and we do not wish the formatting to carried over these as its confusing people.

    I have looked at the docs and saw: dbr.cellstyle

    Which I could possibly use to get this working. My issue here is the syntax of this.
    From the example we have:

    select 'dbr.cellstyle', 'value', 'style';

    select name, Month, value as '[value]', if (value<14,'color:red','color:green') as '[style]'

    But to what is is referring to by 'value' and 'style'?

    Am I just being slow here?

  2. myDBR Team, Key Master

    Hi,
    dbr.cellstyle is a command that accepts two parameters. First parameter is the ColumnReference (column number or reference name) of the column whose style you wish to chhange. The second parameter is the ColumnReference to a column where the style can be found. (ColumnReference is either the column name or if the name includes square brackets, then the text inside the brackets.)

    You've got command:

    select 'dbr.cellstyle', 'value', 'style';

    i.e. you wish to set the 'value'-columns CSS-style to the definition found in 'style'-column.

    --
    myDBR Team

  3. SBurke, Member

    So if I were to simply put:

    select 'dbr.cellstyle', 4, 7;

    That would then mean it would look at cell 7 for the correct formatting of cell 4?

    At present with the report I am doing this with column 7 either contains "mydbr_style('Highlight Yellow')" or "0" where 'Highlight Yellow' is a style we already have defined.

    What is happening is that although I now get no errors I am not getting any formatting either.

  4. myDBR Team, Key Master

    select 'dbr.cellstyle', 4, 7;

    That would then mean it would look at cell 7 for the correct formatting of cell 4?

    Right. We advise moving away from the column numbers though and use the ColumnReferences (i.e. names). Makes your life much easier when maintaining the reports.

    What is happening is that although I now get no errors I am not getting any formatting either.

    Please show the query. It is easier to see what is the cause when one sees the query.

    --
    myDBR Team

  5. SBurke, Member

    Currently the code is as follows:

    i have it set to still highlight the entire row, but the ultimate aim is to only have columns 4 onwards highlighted.

    CREATE DEFINER=root@localhost PROCEDURE blah( inStartDate date, inEndDate date, inVendor varchar(45), inCurr varchar(3), inRetailer varchar(45)

    ) BEGIN

    select 'dbr.export.options', 'orientation', 'landscape'; select 'dbr.export.options', 'autosize', 1; select 'dbr.title', 'Price Scrapper'; SELECT 'dbr.hdr', 1, 2, 3; select 'dbr.rowstyle', 8; SELECT 'dbr.hidecolumn', 8;

    SELECT VendorCode as Vendor, ps.cc_product_code as 'Product Code', Description, pr.retailer_name as 'Retailer', substr(max(datetime),1,10) as Date, value as 'Price (excl VAT)', psp.page_url AS URL, 0 FROM typ.tscrscrapes as ps

    join typ.tpriceproducts as pp on code = ps.cc_product_code and active = 'Y' join typ.tscrretailers as pr on ps.cis_account_code = pr.cis_account_code left join typ.tscrproducts as psp on product_id = psp.id

    WHERE CASE when (inVendor LIKE 'all vendors' ) then VendorCode LIKE '%' else VendorCode LIKE CONCAT(inVendor, '%') end AND pr.cis_account_code LIKE IF(inRetailer IS NULL, '%', CONCAT(substr(inRetailer,1,6), '%')) AND datetime between CONCAT(inStartDate, ' 00:00:00%') AND CONCAT(inEndDate, ' 23:59:59%') AND value IS NOT NULL AND jshop_currency_code like concat('%',inCurr,'%') group by ps.cc_product_code, Description, pr.retailer_name, value, GBPRrp, GBPWebToday

    union all select distinct vendorcode, code, description, 'ColorConfidence', substr(sysdate('yyyy-mm-dd'),1,10), CASE inCurr WHEN 'GBP' THEN gbpwebtoday WHEN 'EUR' THEN eurwebtoday WHEN 'PLN' THEN plnwebtoday ELSE gbpwebtoday END as Price, NULL, mydbr_style('Highlight Yellow') from typ.tpriceproducts as prod join typ.tscrscrapes as s on s.cc_product_code = code and datetime between CONCAT(inStartDate, ' 00:00:00%') AND CONCAT(inEndDate, ' 23:59:59%') where CASE when (inVendor LIKE 'all vendors' ) then VendorCode LIKE '%' else VendorCode LIKE CONCAT(inVendor, '%') end and active = 'Y' order by 1,2,6,5,4;

    END

  6. myDBR Team, Key Master

    So you have two selects with union. The first select returns a rowstyle 0 (should be an empty string '') and therefore no row formatting is done for those rows.

    The second part of the union uses rowstyle 'Highlight Yellow' for the rows coming from that query. You can check what is the output of:
    select mydbr_style('Highlight Yellow');

    You can highlite the specific columns using dbr.cellstyle. The dbr.rowstyle applies the style for full row. To debug the output, temporarily remove the dbr.hidecolumn, so you see what the style of the row should be.

    --
    myDBR Team

  7. SBurke, Member

    Thank you for the response.

    Using dbr.rowstyle on this report works as expected. The CSS is returned correctly (else rowstyle would not work either?). However if I set dbr.cellstyle instead of dbr.rowstyle it does not apply formatting.

  8. myDBR Team, Key Master

    Could you show an example that is not working?

    Here is a simple example of dbr.cellstyle:

    select 'dbr.cellstyle', 'value', 'style';
    select 'dbr.hidecolumn', 'style'; select 'No style', 'With style' as 'value', 'background-color:yellow' as 'style';

    --
    myDBR Team

  9. SBurke, Member


    SELECT 'dbr.cellstyle', 4,8;
    SELECT 'dbr.hidecolumn', 8; <snip> SELECT distinct vendorcode, code, description, 'ColorConfidence', substr(sysdate('yyyy-mm-dd'),1,10),
    CASE inCurr
    WHEN 'GBP' THEN gbpwebtoday
    WHEN 'EUR' THEN eurwebtoday
    WHEN 'PLN' THEN plnwebtoday
    ELSE gbpwebtoday
    END as Price,
    NULL, mydbr_style('Highlight Yellow')
    FROM
    <snip>

    Where Highlight Yellow is defined as: [color: white; background-color: NavajoWhite;]

  10. myDBR Team, Key Master

    The dbr.cellstyle style definition is plain css (like rowstyle), so try to remove the square brackets from the style definition.

    --
    myDBR Team

  11. SBurke, Member

    Than you for the suggestion. However rowstyle works exactly as expected. So does that mean that cellstyle and rowstyle need different style definitions?

  12. myDBR Team, Key Master

    Rowstyle and cellstyle are both plain css, nothing else.

    Colstyle differs from others since it has also the formatting part and possibility to assign different styles for negative, zero and positive values. Square brackets are used to separate different definitions parts.

    --
    myDBR Team

  13. SBurke, Member

    So Im now even more confused in that why rowstyle works then?

    So rowstyle works when it shouldnt? and cellstyle doesnt work because it needs CSS without square brackets?

  14. SBurke, Member

    removing the square brackets solved the mystery of why cellstyle did not work, but im still confused why rowstyle works with square brackets?

  15. myDBR Team, Key Master

    Rowstyle is by definition just a style, no other functionality is included. Therefore you should not use square brackets in rowstyle.

    If you pass incorrect CSS to the browser, different browsers may interpret it differently.

    --
    myDBR Team


Reply

You must log in to post.