So just a few things to clean up on this page before we move on, and I give you a challenge.
And first of all, I'm looking right now at old dash sales page HTML in the fetch statement at the bottom
of that file, and it works pretty well.
But of course, we're not checking for some obvious things.
What if there are no sales, for example?
Well, this for each will never execute.
We probably want to display something saying there are no sales.
So what I'll do is just before this, a very simple check if data, if that's not equal to know because
we'll be getting null.
If there is no data, then I'll come down here, close that if statement and just put it in and close
that up and tab things over so things are a little more visually appealing.
I can get rid of this console log data because you don't need that anymore.
If there is no data, then I'll again get a reference to the Tebaldi for inserting a row and create
an empty.
So I'll put those right here and tab this one back.
So I have a row and I have a cell now.
I want this cell to have a couple spent attributes at the.
And that's easy enough.
So it's an attribute called spane for and I'll said it's interreg html.
So Interreg HTML is going to be equal to
no data available.
OK, so there's the first thing, the next thing we want to do is to format currency to make it a little
more attractive than it is right now because we're displaying it simply a sense.
So we'll go outside of my statement and read a function which I'll call format currency and it will
take the amount which comes as sense, and we'll just adjust that format it the way we want it to be.
So I'll say let the variables see equal to that.
I'll pass float to get it into the form that I want, which is a floating point number, the amount
which I received as a parameter divided by one hundred.
And then I will simply say return using c dot to local string, which I better spell.
Right.
And this is built right into pretty much every browser out there right now.
My currency's Canadian.
You can use whatever your currency is in yen for English, Deshchytsia for Canada and then curly brackets
and close my curly brackets and it's really straightforward.
I say style is going to be currency
and the currency in my case is equal to see.
Now you can use that value from the database and convert it to uppercase if you want to.
But I only care about Canadian currency right now, so I'll just do it this way.
So now that I have this function available, I can I can come back up here before I display the amount
in that cell and simply say let cur for currency equal the function.
I just wrote format currency and pass it I transaction amount.
And down here where I create the text node, I'll put her in there.
All right, let's try that.
So make sure everything is running.
Nothing else.
So make start back.
And I'll run air in case I have a typo, which I often do, go back to my Web browser, reload this
to see if I'm logged in.
I'm not.
So let me log in admin at example.
Dot com password p.
S s w r d and try logging in.
There we are.
Let's go to admin all sales and they're they're displaying the way they should be.
Now, if I go back to my database and look at my Transat or my orders and look at the content, I just
delete everything in here.
So I'll delete those.
And come back here now and refresh this, it should give me the call span four with no data available
and it does.
All right.
So that's pretty good.
Now, obviously, there are more things we could do here.
And you may have your own favorite JavaScript library for displaying tabular data.
And that's easy enough to implement.
There are many, many to choose from.
The only other thing I really need to worry about at this point is what happens when I'm really successful
and I have twenty thousand or 50000 orders.
Right now, we're going to be getting all 50000 orders and trying to display them in a single table,
and that's really inefficient.
So we're going to want to chunk our data and we'll get started on that before too long before we do
that.
I have a challenge for you, which I'm going to give you in the next lecture.