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

Added all dt event emitters #15

Merged
merged 3 commits into from Feb 8, 2023
Merged

Added all dt event emitters #15

merged 3 commits into from Feb 8, 2023

Conversation

LittleLama
Copy link
Contributor

Adding DT event emitters at component scope to let trig event listeners to parent component. By example to get selected row, to style after draw ...

Adding DT event emitters at component scope to let trig event listeners to parent component. By example to get selected row, to style after draw ...
Copy link
Contributor Author

@LittleLama LittleLama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace dt instance in event emitted

Fixed ref to DT API
Copy link
Contributor Author

@LittleLama LittleLama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed DT API call for event emitters

@LittleLama
Copy link
Contributor Author

Now when you call your DataTable component you can pass as props callbacks for all DT events as @draw, @order, @select ...

<DataTable			
    :columns="columns"
   :options="options"
   :data="data"
   @draw="drawCallback"
   ref="table"
 />		

drawCallback(){ console.log("Draw"); }

@AllanJard
Copy link
Contributor

Cool - thanks for this. Are you happy for this to be included under the MIT license?

@LittleLama
Copy link
Contributor Author

For sure.
I'm glad to help.
Best regards

@AllanJard AllanJard merged commit 60797ca into DataTables:main Feb 8, 2023
@LittleLama LittleLama deleted the patch-1 branch February 8, 2023 11:12
@AllanJard
Copy link
Contributor

I'm having trouble compiling this change.

this.$emit(eName, { event: event, dt: dt });

is resulting in:

src/datatables.net-vue.vue:156:5 - error TS2532: Object is possibly 'undefined'.

156     this.$emit(eName, { event: event, dt: dt });

Reading this issue it appears that the event cycle hooks don't have access to this any more. Are you familiar with any of those changes? Its the first I've encountered it and I'm not sure what the fix is.

@LittleLama
Copy link
Contributor Author

Hi Allan
No I think it is only due to to TypeScript syntax. I got no problem accessing this from DT even when destroying it.

Maybe should I declare types of event parameters emitted regarding this thread. I'm not familiar with TypeScript at all. Will give a look.

https://itsjavascript.com/object-is-possibly-undefined-error-in-typescript?utm_content=cmp-true

@AllanJard
Copy link
Contributor

Thanks for the reply. I was getting errors unfortunately, but I found the solution was to use getCurrentInstance() from Vue and then call emit on that. That seems to do the business.

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

Successfully merging this pull request may close these issues.

None yet

2 participants