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

How to add filter param in vue 3 datatable? #13

Open
andykoe24 opened this issue Jan 5, 2023 · 12 comments
Open

How to add filter param in vue 3 datatable? #13

andykoe24 opened this issue Jan 5, 2023 · 12 comments

Comments

@andykoe24
Copy link

andykoe24 commented Jan 5, 2023

hi, how can i add filter param in ajax call?

sample from image 1 is vue 3 version, image 2 is jquery version which can add param easily. i cant find anything regarding ajax->data in your website. it is posible to do it in vue 3 datatable right?

And what if i want to destroy and init table again, how to do that?

image

image

@AllanJard
Copy link
Contributor

The ajax attribute just maps directly to the DataTables ajax option, so you can give it an object as well as a string, which is how you would do it.

@andykoe24
Copy link
Author

andykoe24 commented Jan 6, 2023

ok, will try it out.

How about reinitialize datatable using vue 3 plug in method?

@andykoe24
Copy link
Author

Hi Allan, the options you suggest is working fine, thanks for that.

Now left the reinitialize datatable/draw method.

@AllanJard
Copy link
Contributor

You could use the destroy option if you wanted to re-init it. There isn't a Vue specific API that I've exposed for that.

@avpet979
Copy link

avpet979 commented Feb 6, 2023

Hi everybody!
is there any working example with ajax custom filtering?

@AllanJard
Copy link
Contributor

What kind of custom filtering? A DataTables search plug-in, column filtering, something else? The answer is likely no there isn't a Vue specific example, but almost all the DataTables examples can be adapted for the Vue integration plugin.

@avpet979
Copy link

avpet979 commented Feb 6, 2023

What kind of custom filtering? A DataTables search plug-in, column filtering, something else? The answer is likely no there isn't a Vue specific example, but almost all the DataTables examples can be adapted for the Vue integration plugin.

i understand about ajax_url and params for custom column filters, but i failed to make destroy/redraw method work

@AllanJard
Copy link
Contributor

I'm not sure how destroy / redraw relates to your question about custom Ajax filtering. Perhaps you can link to an example that shows what you've got at the moment.

@avpet979
Copy link

avpet979 commented Feb 6, 2023

i'm talking about param filtering, sorry.

        <input type="text"  v-model="ajax_request.data.name">
        <DataTable 
            :columns=columns
            :options="{ 
                select: true,
                serverSide: true,
            }"
            :ajax=ajax_request
            ref="table"
        >
  columns: [
      { data: 'name' },
      { data: 'actions',},
  ],
  ajax_request: {
      url:'/get_data/',
      data: {
          name: null,
      }
  },

jQuery has .draw() method to refresh table by filtering parameter on input change or button submit. In this example i have just one filter and here i can use global filter. But my task is to make advanced filter with checkboxes and radio buttons. And i can't to make it work.

@wdporter
Copy link

wdporter commented Feb 6, 2023 via email

@AllanJard
Copy link
Contributor

You can to some extent, particularly if you add v-once to the container. DataTables controls the DOM for the table, not Vue (having them both try to control it would be a disaster, and that's way v-for can't be used to populate the table - it must be loaded in by the DataTables ajax or data parameters. So DOM manipulation such as the example linked to there, can work, just be aware of the potential issues.

jQuery has .draw() method to refresh table by filtering parameter on input change or button submit

DataTables has a draw() method, not jQuery. And you can access the DataTables instance that this plug-in uses through the dt parameter. As such you can call draw() on that if that is what you need.

You can also use ajax.data as a function (see reference here) to dynamically get and update data whenever the request is made.

@avpet979
Copy link

avpet979 commented Feb 7, 2023

Allan, thanks a lot for your help. Param filtering is working just fine!
i've read the vue docs carefully and fix my errors.

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

No branches or pull requests

4 participants