SQLpage icon indicating copy to clipboard operation
SQLpage copied to clipboard

datetime formatting with natural sorting in the table component

Open vks2 opened this issue 8 months ago • 4 comments

Hello, just some typical and simple questions

  1. If i want to render datetime value coming from SQL query in table component, do i need to write handlebars?
  2. If i want to colorize a row if the value coming from sql is true or false (bool field) I also need to make a handlebars? 3.sadly that pagination = true in table component is not yet developed, it's a basic function in all similar libs

thanks much for your work

vks2 avatar Apr 25 '25 02:04 vks2

Hi !

If i want to render datetime value coming from SQL query in table component, do i need to write handlebars?

No you don't. Are you having issues with rendering datetimes ? Can you tell us more about the issue you are having ? What database are you using, what does your table schema look like, what query are you using ?

If i want to colorize a row if the value coming from sql is true or false (bool field) I also need to make a handlebars?

No, you can use a case expression.

For instance

select 'list' as component;

select 
  title,
  case when has_errors then 'red' else 'blue' end as color
from orders;

3.sadly that pagination = true in table component is not yet developed, it's a basic function in all similar libs

Pagination is hard to implement in a way that is both

  • generic (allowing the developer to use it with any query they want)
  • and efficient (not downloading the entire result set at once on the client)

It is definitely possible, though. Contributions welcome !

lovasoa avatar Apr 28 '25 08:04 lovasoa

yes, i'm backed by a postgres tables. i need to keep datetime format (to filter properly) but to be able to show custom date formats at a table. alsoo i need to colorize rows by an easy rule, if a col is bool true the row is green. is it easely doable? thanks much, for a half of a year you did a tremendous work Best

vks2 avatar Apr 28 '25 08:04 vks2

of course every dev is dreaming about opensource contribute to a high stared project. but we also have severe time constraints. so hopefully anyday our dreams will com true

vks2 avatar Apr 28 '25 08:04 vks2

Oh, I see, you would like something similar to what we have for money in the table component ? https://sql-page.com/component.sql?component=table

Show the values with a certain format, but sort them according to their natural order, not to the format string ?

That is not yet implemented, but wouldn't be hard to do, reusing the same logic as we have for money columns. Pull requests welcome ! The code you will need to update is here: https://github.com/sqlpage/SQLPage/blob/main/sqlpage/sqlpage.js#L42

lovasoa avatar Apr 28 '25 08:04 lovasoa