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

[Feature Request] Allow to provide custom table-body implementation #14471

Closed
stalniy opened this issue Feb 24, 2019 · 17 comments
Closed

[Feature Request] Allow to provide custom table-body implementation #14471

stalniy opened this issue Feb 24, 2019 · 17 comments
Labels
Projects

Comments

@stalniy
Copy link

stalniy commented Feb 24, 2019

Existing Component

Yes

Component Name

el-table

Description

I want to implement infinite scrolling by using el-table component and track visible page with IntersectionObserver API.

For example, each page contains 50 elements. I want to group 50 <tr> tags inside one <tbody>. In such way, each tbody contains elements for a single page. Then I can track when one tbody appears and another disappears to track when to switch page parameter in browser url.
Currently I can do this by overwriting Table.components.TableBody but this is a hacky solution.

So, there are several ways to fix this:

  1. Implement a factory function which can create Table component on the fly with specified parts:
import { createTable } from 'element-ui'

const Table = createTable({
  body: MyCustomBody, 
  footer: MyCustomFooter
})
  1. A bit simpler: split Table's render function into several smaller functions (e.g., renderBody, renderFooter, etc). So, then I can extend component and overload that functions:
export default {
  name: 'MyCustomTable',
  extends: ElTable,
  methods: {
    renderBody(context) {
      return this.$createElement(MyCustomBody, context)
    } 
  }
}
@stalniy
Copy link
Author

stalniy commented Feb 24, 2019

By the way, I can create a PR for the 2nd solution if you like it

@island205
Copy link
Contributor

Why not add infinite scrolling feature to el-table directly?

@iamkun iamkun added this to the 2.7.0 milestone Mar 5, 2019
@stalniy
Copy link
Author

stalniy commented Mar 5, 2019

Better to add an extension point. I want to track pages using IntersectionObserver, somebody else will want to implement virtual scrolling (reusing DOM elements) and so on.

That’s why I suggest to reuse existing functionality with an ability to make something custom.

@island205
Copy link
Contributor

got it , Would you like provide an simple implement?

@stalniy
Copy link
Author

stalniy commented Mar 6, 2019

Sure, I’ll be able start working on 2nd approach either on this weekend or the next

@island205
Copy link
Contributor

Thank you.

@iamkun
Copy link
Member

iamkun commented Mar 27, 2019

Any updates here?

@iamkun iamkun modified the milestones: 2.7.0, 2.8.0 Mar 27, 2019
@stalniy
Copy link
Author

stalniy commented Mar 27, 2019

Haven’t had time to work on this. Plan to do it this weekend

@iamkun
Copy link
Member

iamkun commented Mar 27, 2019

Take your time, please.

@stalniy
Copy link
Author

stalniy commented Mar 30, 2019

After thinking about implementation details, I found out that it's much easier to implement 1st option. It can be done like this:

import Table from 'element-ui/lib/table'
import MyTableBody from './MyTableBody.vue'

export default {
  name: 'MyTable',
  extends: Table,
  components: {
     TableBody: MyTableBody
  }
}

The same can be done to any part of ElTable component. So, here is my updated plan:

  • refactor TableBody render function to make it more customizable (in case somebody like me wants to extend it :))
  • export TableBody as a public component, so it's possible to import it `import TableBody from 'element-ui/lib/table-body' and extend
  • ensure that the code above works as expected

@iamkun @island205 are you ok with that approach?

@stalniy
Copy link
Author

stalniy commented Mar 30, 2019

is it possible to import Vue or some element-ui components in :::demo blocks in docs (can't do this...., want to show a simple example of how to implement custom table body)

@island205
Copy link
Contributor

@stalniy modify examples/play/index.vue file, use the component you want, then run npm run dev:play, go ahead http://localhost:8085 .

https://github.com/ElemeFE/element/blob/master/.github/CONTRIBUTING.en-US.md#prerequisites

@stalniy
Copy link
Author

stalniy commented Apr 1, 2019

That works. Bu the question is about examples/docs/table.md file. I’m trying to use importstatement in example code (wrapped in :::demo container) and it fails saying that import/export is allowed only on top level (looks like import/export is not transpiled in that block)

@iamkun
Copy link
Member

iamkun commented Apr 1, 2019

We do not support import syntax in :::demo container as the moment.

@stalniy
Copy link
Author

stalniy commented Apr 5, 2019

I see.

Created PR without updates to documentation.

@island205
Copy link
Contributor

@stalniy we will check your PR soon.

@ziyoung ziyoung modified the milestones: 2.8.0, 2.9.0 Apr 25, 2019
@luckyCao luckyCao removed this from the 2.9.0 milestone May 30, 2019
@ziyoung ziyoung added this to To do in ElTable Jun 3, 2019
@stale
Copy link

stale bot commented May 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 29, 2020
@stale stale bot closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
ElTable
  
To do
Development

Successfully merging a pull request may close this issue.

5 participants