nithinmurali / pygsheets

Google Sheets Python API v4
https://pygsheets.readthedocs.io/en/latest
Other
1.51k stars 220 forks source link

Add setBasicFilter #509

Closed rariyama closed 2 years ago

rariyama commented 3 years ago

Thank you for providing this useful library with us.

Is your feature request related to a problem? Please describe. I would like to set a filter on a specific sheet with this library. Does pygsheets support setBasicFilter functions which can set a filter on spreadsheet? https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#setbasicfilterrequest If not, are there any plan to implement function supporting this API request?

Describe the solution you'd like I would like you to add set_basic_filter function on Worksheet class. https://github.com/nithinmurali/pygsheets/blob/staging/pygsheets/worksheet.py#L37 It'll be possible to implement by calling SetBasicFilter request with batch_update function. https://github.com/nithinmurali/pygsheets/blob/staging/pygsheets/sheet.py#L61-L120 An example code follows.

        data_range = {
            'sheetId': target_sheet.id,
            'startRowIndex': 1, 
            'startColumnIndex': 0,
        }
        set_basic_filter_request = {
            'setBasicFilter': {
                'filter': {
                    'range': data_range,
                }
            }
        }
        self.client.sheet.batch_update(spreadsheet_id, set_basic_filter_request)

Any other info I would like to support as much as possible if this request is needed.

nithinmurali commented 2 years ago

Hi, currently there is no direct method to implement this. But you can do this using cutom_method.

This is in pipeline, but this needs a lot of supporting models like sortSpec, FIlterCriteria, FilterSpec.

ahathaway commented 2 years ago

Hi, currently there is no direct method to implement this. But you can do this using cutom_method.

This is in pipeline, but this needs a lot of supporting models like sortSpec, FIlterCriteria, FilterSpec.

@nithinmurali Please elaborate on what you mean when you say "custom_method". Is there currently a documented way to introduce custom sheets api calls using pygsheets? Thank you!

nithinmurali commented 2 years ago

Hi @ahathaway, Unfortunately, there are no docs on the custom_request.

but the basic outline is

      # look at the [API docs](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#setbasicfilterrequest) the create the request dict
        data_range = {
            'sheetId': target_sheet.id,
            'startRowIndex': 1, 
            'startColumnIndex': 0,
        }
        set_basic_filter_request = {
            'setBasicFilter': {
                'filter': {
                    'range': data_range,
                }
            }
        }
      # send the dict to custom_request of the spreadsheet
       sh.custom_request(set_basic_filter_request, fields="*")
ahathaway commented 2 years ago

Hi @ahathaway, Unfortunately, there are no docs on the custom_request.

but the basic outline is

      # look at the [API docs](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#setbasicfilterrequest) the create the request dict
        data_range = {
            'sheetId': target_sheet.id,
            'startRowIndex': 1, 
            'startColumnIndex': 0,
        }
        set_basic_filter_request = {
            'setBasicFilter': {
                'filter': {
                    'range': data_range,
                }
            }
        }
      # send the dict to custom_request of the spreadsheet
       sh.custom_request(set_basic_filter_request, fields="*")

@nithinmurali Thank you!

rariyama commented 2 years ago

Thank you for describing it to us. If there is no need to implement the new function, I will close this issue.Let me know if you need my support to implement the direct method.

nithinmurali commented 2 years ago

Hi @rariyama , If you could create a PR for the same it would be great. It should be a fairly straightforward. You look at sample implementations for reference.

nithinmurali commented 2 years ago

Thanks, @rariyama for the PR. closing this issue as the PR is merged.