GithubHelp home page GithubHelp logo

Comments (2)

ibdafna avatar ibdafna commented on May 17, 2024

Hello again @sachin-smart and thank you for the feature suggestions!

ipydatagrid was designed to be extended using the widget ecosystem, and therefore it is probably not within scope to incorporate rendering logic based on data type - that logic is something users can implement using the existing Python language constructs.

To your point on using a single, default renderer for the grid - this exists and is actually well documented in the examples folder. All of ipydatagrid's documentation is example based. We can also use basic Python to implement logic for selecting a different header renderer for each column based on its data type. See below for a short example which achieves that:

import pandas as pd
import numpy as np
import ipydatagrid as datagrid

data = pd.DataFrame({'Integer':[1,2,3,4,5], 
                     'Float':[1.1, 2.2, 3.3, 4.4, 5.5],
                     'Text':'A B C D E'.split(), 
                     'Dates':pd.date_range(start='2021-06-01', end='2021-06-05'),
                     'Mixed':[1, 2.2, 'C', np.datetime64('2021-05-05'), 5]})

default_renderer = datagrid.TextRenderer(background_color="salmon")
string_renderer = datagrid.TextRenderer(background_color="limegreen")
int_renderer = datagrid.TextRenderer(background_color="yellow")

dtype_renderers = {
    np.dtype('int64'): int_renderer,
    np.dtype('O'): string_renderer
}

column_renderers = {name:dtype_renderers[dtype] for (name, dtype) in data.dtypes.items() if dtype in dtype_renderers}
grid = datagrid.DataGrid(data, 
                         default_renderer=default_renderer, 
                         renderers=column_renderers,
                         layout={"height":"150px"})
grid

from ipydatagrid.

sachin-smart avatar sachin-smart commented on May 17, 2024

That's great. Much appreciated! And apologies, I did not see the full extent of examples or the usage of default_renderer. Cheers!

from ipydatagrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.