mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
710 stars 53 forks source link

SearchBuilder Requires DateTime when used with dates. #288

Open pali07 opened 3 weeks ago

pali07 commented 3 weeks ago

image

Can anyone please help me with this issue. unable to install the datetime library

mwouts commented 3 weeks ago

Hi @pali07 , thanks for reporting this.

Could you show us the error message, and copy your example as text too? Thanks!

pali07 commented 3 weeks ago

Not getting any error message getting table but search builder is not working image

After clicking on searchbuilder button the output is as follows

image

pali07 commented 3 weeks ago
import pandas as pd
from itables import init_notebook_mode, show
from datetime import date, datetime

init_notebook_mode(all_interactive=True)

def convert_to_table(data, description=None, column_names=None, specified_columns=None):

    df = pd.DataFrame(data, columns=column_names)
    if column_names is None and df.columns.nlevels == 1:
        column_names = df.columns.tolist()
    if column_names:
        column_names = [col.strip('_').capitalize() for col in column_names]
        df.columns = column_names

    if specified_columns:
        df = df[specified_columns]

    show(
        df,
        classes="display nowrap cell-border top-border",
        scrollX=True,
        dom="Bfrtip",
        buttons=[
            "colvis",
            "pageLength",
            {
                "extend": "collection",
                "text": "Export",
                "buttons": [
                    {"extend": "csvHtml5", "title": "data"},
                    {"extend": "excelHtml5", "title": "data"}
                ]
            },
            "searchPanes",
            "searchBuilder"
        ],
        select=True
    )
data = {
    'Title': ['1Password', '1Password', '1Password'],
    'Name': [12296, 24812, 25516],
    'AnyDateColumn': ['2023-04-19', '2023-04-18', '2023-04-18']
}

convert_to_table(data)
pali07 commented 3 weeks ago

Hi @mwouts Thanks for the quick reply

mwouts commented 2 weeks ago

Thanks for the detailed information! I can reproduce the issue, that's a first step. I think we should be able to add the datetime extension, cf. the linked PR, although it's not working right now...

At the moment I am getting the following error: Uncaught ReferenceError: assignment to undeclared variable dt (and no table can be displayed). I might have to see on the datatables forum for how to get this PR right. I will keep you posted.

rsnell-usgs commented 1 week ago

+1 for this issue. Same error for a table that includes dates as a column.

DataTables discussion on this: https://datatables.net/forums/discussion/76107/searchbuilder-requires-datetime-when-used-with-dates#Comment_220274

mwouts commented 6 days ago

Oh that was helpful! I followed the first comment that points to the download builder and I could install the DateTime package.

@rsnell-usgs @pali07 feel free to use the install instructions at https://github.com/mwouts/itables/pull/289#issuecomment-2159267444 to test the PR locally.

I am not going to merge this right now as I still see a small issue, I will discuss it with Allan on the PR.