if statement
if statement
raspoteen
Posts: 16Questions: 8Answers: 0
Hi, I want to check the Currency for each raw, and I tried this code but it is not working any more
//Check the Buy Price Dollar Or Dinar
if ({data: "buy_currency"} == "1") {
return {data: "buy_price", render: $.fn.dataTable.render.number( ',', '.', 0, '$') },
else return {data: "buy_price", render: $.fn.dataTable.render.number( ',', '.', 0) },
}
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Where is that code executed? Could you give me some context? Are you getting an error shown in your Javascript console?
Allan
this code is never executed. it's full with errors
but i want the right code to add [$] to the price when the buy_currency field is "1"
Note// my back end in Laravel
i had to do something similar before but i didn't use $.fn.dataTable.render for any of my formatting, it looks like youre doing this in your column defines as a render function, will something like this work if so?
@crwdzr your code looks great, but i want to check the currency in the (buy_currency) column then apply the dollar sign to the (buy_price) column ,,, you got me ?
oops, my bad. in that case just plop it in the buy_price column define
when you use the render function like this you can compare the data arg (which is the cell's data) to the row arg (which contains the data for the entire row it belongs to), its really helpful once u start getting the hang of it.
like i said though i've never used any $.fn.dataTable.render functions so I dont know if $.fn.dataTable.render.number will work in this context
You can apply crwdzr's solution in the
buy_price
column. The row parameter contains all the data for that row. Thecolumns.render
docs explain what the function parameters.Kevin
crwdzr's code is right, but missing one thing, how to apply this code
to the buy_price field ??
I was just looking at some examples of that render.number() helper cause this is something i'll start using, to use it inside a render function, just add .display(data) to the end of each render.number()
@crwdzr it's Working, and It's Great, thanks so much
@kthorngren and thank you too.