• Resolved mcreighton

    (@mcreighton)


    How do I format columns output via publisher. In particular I need to add currency symbols to numbers stored in a specific column from the underlying table?

    Hopefully my last cry for help today – the fact I’ve only had a couple of queries (touch wood) demonstrates just how easy it has been to implement.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @mcreighton,

    There are (at least) two ways to do this:
    (1) Use a column renderer
    (2) Use fnRowCallback

    In both cases you need to insert javascript code in table options advanced. Examples of a column renderer can be found here:
    https://datatables.net/reference/option/columns.render

    But fnRowCallback is easier for your use case. An example can be found here:
    https://wpdataaccess.com/docs/documentation/data-publisher/advanced-settings/
    Look for “Add javascript function which sets color depending on content (more complex):”

    Suppose the index of your column is 1, your code could be something like this:
    “fnRowCallback”: “function(row, data, index) { console.log(data[1]); jQuery(row).find(‘td:eq(1)’).text(‘$ ‘ + data[1]) }”
    > NOT TESTED!

    Let me know if this helps… ??
    Peter

    Thread Starter mcreighton

    (@mcreighton)

    Thanks v much and t probably would help – if only I knew what I was doing ??

    I’ve entered the following in the table options/advanced:

    { “fnRowCallback” : function(row, data, index) { console.log(data[2]); jQuery(row).find(‘td:eq(2)’).text(data[2]+’C’) }

    And I am told there is a parse error in line 1 – expecting string etc, got undefined.

    I have had a quick look at various coding sites but that just made my head spin. I can understand the logic of whqt the code should be doing but can’t see what I need to do to make it work.

    Sorry

    Mike

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Mike,

    Webservers replace quotes with their versions of it, which is not valid json. Sorry, I should have known… ?? Please try this code:

    { "fnRowCallback" : "function(row, data, index) { console.log(data[2]); jQuery(row).find('td:eq(2)').text(data[2]+'C')" }

    Hope this helps ??
    Peter

    Thread Starter mcreighton

    (@mcreighton)

    Well that worked in so far as no error messages. But no data returned either as you can see on this Dummy Page.

    I don’t know if it helps but when I enter your new code into the advanced area it doesn’t take on the colour coding of the various elements that I usually see.

    Nearly, but not quite.

    Sorry.

    Mike

    try this

    { "fnRowCallback" : "function(row, data, index) { console.log(data[2]); jQuery(row).find('td:eq(2)').text(data[2]+'C')}" }

    an extra right brace near the end

    Thread Starter mcreighton

    (@mcreighton)

    Nailed it. Well done.

    If you have the time or willingness to explain how that made a difference to a coding novice….

    Either way, much appreciated.

    Mike

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Format columns in publisher’ is closed to new replies.