Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why Aren't Pivot Table Properties Applied When Configured via Client-Side Code in Anvil? #531

Open
jrperassoli opened this issue Apr 20, 2024 · 8 comments

Comments

@jrperassoli
Copy link

Hi,

I'm attempting to configure the properties of the pivot table using client-side code, but the settings are not applied when the table is loaded. However, these properties work perfectly when adjusted directly from the Anvil IDE. Why don't these settings take effect when made from the client-side code?

Example of code that is not working:

class Form1(Form1Template):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    json_data = anvil.server.call('df')
    # Convert JSON string to list of dictionaries
    items = json.loads(json_data)
    # Set the items for the pivot table
    self.pivot_1.items = items
    # Configure your pivot table here
    self.pivot_1.rows = ["sectors"]
@s-cork
Copy link
Collaborator

s-cork commented Apr 20, 2024

Looking at the code it's just not implemented. Only options passed as properties during instantiation have an effect. And code to update those options doesn't exist. Are you interested in making a PR? Or do you want this to be a feature request for someone else to implement?

If you want to look at writing a PR we can point you in the right directions.

@meatballs
Copy link
Member

Yep, that's not implemented

@jrperassoli
Copy link
Author

Hello, thank you for your quick reply. Yes, I'm interested in making a PR. Could you please tell me which folder I should modify the code in? Thank you.

@s-cork
Copy link
Collaborator

s-cork commented Apr 20, 2024

It'll be in the client_code for the pivot component.

You'll need to add a property for rows.
Then you'll need to re-init the jquery pivot table.

If you search jquery pivot table online you'll find documentation for the pivot table. But i think all you need is to call the init table method with the new options.

I looked at some docs and the call to pivotUi will need a third argument set to True which is the override argument.
pivotUI(dom, options, True)

Note the pivot component doesn't store the properties it was given so you'll need to store them.

Some other components store these as self._props. So if you look at examples that do this then you should also find some properties that update the _props.

That might not have been clear enough so shout if you need more details.

@jrperassoli
Copy link
Author

Does it make sense to include this function?

def update_properties_and_refresh(self, **new_properties):
        for prop, value in new_properties.items():
            if prop in self.option_names:
                self.pivot_options[prop] = value
        self._init_pivot()  # Re-initialize the pivot table with updated properties

To later call it with:

self.pivot_1.update_properties_and_refresh(rows=["new"], columns=["new"])

@s-cork
Copy link
Collaborator

s-cork commented Apr 20, 2024

I would just call it update.
And I would simplify the code as

self.pivot_options.update(new_options)

@jrperassoli
Copy link
Author

The code works!

@s-cork
Copy link
Collaborator

s-cork commented Apr 21, 2024

great.

If you need help with creating the PR let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants