Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Formatting in _cm_listView_header() method
Formatting in _cm_listView_header() method [message #2415] Thu, 21 January 2010 15:25 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

Further to all the recent discussion and changes around formatting when producing PDF output I have a question about formatting when using the _cm_listView_header() method. I've recently moved some code that sets substitution tokens into this method (it's where it should have been anyway) but the standard date formatting does not seem to be applied.

Is there something about the order of events for printing the header that I need to take into account?

Thanks.
Re: Formatting in _cm_listView_header() method [message #2416 is a reply to message #2415] Thu, 21 January 2010 18:00 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
No formatting is applied after any call to the _cm_listView_header() method as the header does not contain any variables, just headings.

Have you tried calling the formatData() method yourself?


Re: Formatting in _cm_listView_header() method [message #2417 is a reply to message #2415] Thu, 21 January 2010 18:23 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I've just tried putting the following code as the first line in _cm_listView_header()

$rowdata = $this->formatData($rowdata);


Unfortunately, this seems to have the effect of removing some of the data (I've not debugged properly to see why yet).

However, would it not be appropriate to have the $rowdata that is passed into _cm_listView_header already formatted so that any substitution tokens are formatted correctly in advance?
Re: Formatting in _cm_listView_header() method [message #2418 is a reply to message #2415] Thu, 21 January 2010 18:28 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I've fixed the missing data problem - I put the code in the wrong place. However, the question I asked is still valid.

Graham
Re: Formatting in _cm_listView_header() method [message #2419 is a reply to message #2418] Thu, 21 January 2010 18:33 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
If you step through with your debugger you will see that the formatData() method will format the contents of a row of data according to the field specifications in $this->fieldspec.

If you have a value which is not beig formatted into a date it is because my code does not know that it is a date.


Re: Formatting in _cm_listView_header() method [message #2420 is a reply to message #2415] Thu, 21 January 2010 18:44 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Yes, I had already fixed the problem and the call to formatData is working properly. I really wanted to ask about the necessity to do this manually though as until the recent changes the data was being formatted in the headings without me having to do it specifically.
Re: Formatting in _cm_listView_header() method [message #2421 is a reply to message #2420] Thu, 21 January 2010 19:25 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
See if the attached file fixes your problem.

(attachment deleted)


[Updated on: Fri, 22 January 2010 05:07]

Report message to a moderator

Re: Formatting in _cm_listView_header() method [message #2422 is a reply to message #2415] Fri, 22 January 2010 04:19 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
This version generates an error:

Fatal error: Call to a member function formatData() on a non-object in C:\xampp\includes\std.pdf_list.class.inc on line 25
Re: Formatting in _cm_listView_header() method [message #2423 is a reply to message #2422] Fri, 22 January 2010 05:07 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
Whoops! Embarassed Try This one.

Re: Formatting in _cm_listView_header() method [message #2424 is a reply to message #2415] Fri, 22 January 2010 08:19 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I can work fine with this, although I think the functionality has changed slightly from previously. I see that the data contained in $rowdata within _cm_listView_header() is not formatted, but it gets formatted immediately prior to printing.

I am creating a string of concatenated data into a substitution token, so I have to manually format that data before building the string if I want the correct formats. Tht's perfectly reasonable to expect. Any auto build substitution tokens are being corretly auto formatted now.

Thanks.

Graham
Re: Formatting in _cm_listView_header() method [message #2425 is a reply to message #2424] Fri, 22 January 2010 08:42 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
I had not realised that you expected the data to be formatted BEFORE the call to _cm_listView_header(). Is this what you want?

Which is more logical to you? Perform the formatting on the row data BEFORE or AFTER the call to _cm_listView_header()? This would mean that if you want any changes made in _cm_listView_header() to be formatted then you will have to do it yourself.

It would be a simple cange to make - just move line 22 to below line 25.


Re: Formatting in _cm_listView_header() method [message #2426 is a reply to message #2415] Fri, 22 January 2010 08:59 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I had originally expected the data to be formatted before the call to _cm_listView_header() which is why I was originally struggling with my data. There were actually two problems from my point of view of which your update corrected one (the most important).

Now I'm not sure which approach is more logical to me. I think the current version is probably more consistent with the approach taken throughout the rest of the framework (you are better placed to confirm that). However, the purose of _cm_listView_header() is to modify the contents of the header before printing, so the type of processing most likely to be done is probably easier if the data is already formatted.

I can handle this whichever way now I understand how it is working.
Re: Formatting in _cm_listView_header() method [message #2427 is a reply to message #2426] Fri, 22 January 2010 09:16 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
Upon reflection it would be more logical to format the data BEFORE the call to _cm_listView_header() as you can only modify the contents of the current row.

With the _cm_ListView_print_before() and _cm_ListView_print_after() methods you are not amending the current row but optionally adding new rows, so it is correct that any formatting is done afterwards.

Modified file is attached.


Re: Formatting in _cm_listView_header() method [message #2428 is a reply to message #2415] Fri, 22 January 2010 09:27 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Hmmm. Now that I've tried this I'm not so sure anymore!

Now that the data is formatted I can't easily get back to the id from a value representation to use in another query.

It's swings and roundabouts, although it was probably easier the other way!
Re: Formatting in _cm_listView_header() method [message #2429 is a reply to message #2428] Fri, 22 January 2010 11:38 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
You are confusing me now because your earlier problem was with the formatting of dates.

If you want to stop a ValRep field from being automatically changed into its representation then you need to amend the contents of the $fieldspec entry so that the formatData() method does not overwrite the field value with the external representation.

If you need to work with both the value and the representation you should put two separate fields into the row data before any formatting or custom processing is performed.


Re: Formatting in _cm_listView_header() method [message #2430 is a reply to message #2415] Fri, 22 January 2010 11:42 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

The formatted data now contains data that has been converted by _cm_getValRep(). So $rowdata contains representation data rather than the value.

Prior to te latest change $rowdata contained values rather than representations.

What is the correct/easiest way to obtain the original value for these items?

Sorry - just spotted your previous post so you can ignore this.

[Updated on: Fri, 22 January 2010 11:44]

Report message to a moderator

Re: Formatting in _cm_listView_header() method [message #2431 is a reply to message #2430] Fri, 22 January 2010 11:50 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2370
Registered: April 2006
Location: Surrey, UK
Senior Member
I identified two possibilities in my previous post:
(1) Amend the $fieldspec entry so that the formatData() method will not swap the value with the representation.
(2) After reading the record but before the call to _cm_listView_header() or formatData() put a copy of the original value into the row data with another name. As this will not have an entry in the $fieldspec array it will not be reformatted.

If you need to work with the unformatted value but display the formatted value then I would go for option (2).


Re: Formatting in _cm_listView_header() method [message #2432 is a reply to message #2415] Fri, 22 January 2010 11:55 Go to previous message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Yes, understood - and using option 2 successully as I need both values - one to work with and one to print.

Thanks.
Previous Topic: PDF Footer
Next Topic: Column Filter
Goto Forum:
  


Current Time: Tue Nov 26 09:12:54 EST 2024

Total time taken to generate the page: 0.01534 seconds