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

Table row arbitrary classes. #1797

Merged
merged 6 commits into from May 23, 2018
Merged

Table row arbitrary classes. #1797

merged 6 commits into from May 23, 2018

Conversation

rhangai
Copy link
Contributor

@rhangai rhangai commented May 5, 2018

This PR adds a new type for tbody-tr-class to allow arbitrary per-item classes. (and closes #1795)

<template>
  <div>
    <b-table :items="items" :fields="fields" :tbody-tr-class="rowClass">
    </b-table>
  </div>
</template>

<script>
export default {
  data () {
    return {
      fields: [ 'first_name', 'last_name', 'age' ],
      items: [
        { age: 40, first_name: 'Dickerson', last_name: 'Macdonald', status: 'awesome'  },
        { age: 21, first_name: 'Larsen', last_name: 'Shaw' },
        { age: 89, first_name: 'Geneva', last_name: 'Wilson' }
      ],
    }
  },
  methods: {
    rowClass( item, type ) {
      if ( !item )
        return;
      if ( item.status === 'awesome' )
        return 'table-success';
    },
  }
}
</script>

image

@codecov
Copy link

codecov bot commented May 5, 2018

Codecov Report

Merging #1797 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #1797   +/-   ##
=======================================
  Coverage   61.04%   61.04%           
=======================================
  Files         154      154           
  Lines        2862     2862           
  Branches      791      791           
=======================================
  Hits         1747     1747           
  Misses        800      800           
  Partials      315      315
Impacted Files Coverage Δ
src/components/table/table.js 76.34% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0999b4c...70417dd. Read the comment docs.

@lianee
Copy link
Contributor

lianee commented May 5, 2018

Smart thing to add functions to the existing tbody-tr-class!

Pros:

  • small code
  • can style details, header and footer (better than a items property)

Cons: I don't see any

@amyglock
Copy link

I'm wondering if there is a way to determine if the current row is a detail row my RowClass function?

I am displaying another table component in the detail so I want to shut off the hover color on the detail row because the detail table has hover as well.

@rhangai
Copy link
Contributor Author

rhangai commented May 18, 2018

@amyglock I don't know if it helps, but there is the b-table-details class that it is applied. Also, with this PR, it calls the function with a second argument type that equals "row-details" when being applied to a details row.

@mosinve mosinve merged commit 8e36061 into bootstrap-vue:dev May 23, 2018
@minhnhut
Copy link

Excuse me, I dont know if this is a right place to ask.

When will this feature be available on NPM package?
cause I'm trying to achieve the same thing in my current project.

@valisjan
Copy link

I can't reproduce this funcionality with the above code.
Version 2.0.0rc11
How can I get it?

@minhnhut
Copy link

@valisjan this commit is not included yet. I saw they created a new branch "next-release". But it is still not released yet. I think you have to wait, or you can build your own version.

@valisjan
Copy link

@minhnhut thanks!
How can I build my own version?

@allaghi
Copy link

allaghi commented Sep 20, 2018

I try to implement your code and it gives me error with
Invalid prop: type check failed for prop "tbodyTrClass". Expected String, Array, got Function.

@allaghi
Copy link

allaghi commented Sep 23, 2018

I followed the steps , unfortunately it didn't work , it gives me this message
(Invalid prop: type check failed for prop "tbodyTrClass". Expected String, Array, got Function.)

@nosuchip
Copy link

Merged PR is broken: Invalid prop: type check failed for prop "tbodyTrClass". Expected String, Array, got Function.

@regiscamimura
Copy link

Same issue here, (Invalid prop: type check failed for prop "tbodyTrClass". Expected String, Array, got Function.)

@rhangai
Copy link
Contributor Author

rhangai commented Oct 5, 2018

Well, the branch was merged on May 23, but the latest release is from May 20 (2.0.0-rc.11).
The code is there on the dev branch. You guys can try building from source, just clone it, and run yarn install && yarn run build. I don't think there is anything else to do until a new version is released with these features.

@lojaya
Copy link

lojaya commented Oct 16, 2018

its mid October already, why bootstrap-vue haven't released the next version?

@tmorehouse tmorehouse mentioned this pull request Nov 14, 2018
89 tasks
@rosdi
Copy link

rosdi commented Jan 8, 2019

Can we have it now? :-D

@alaa-aqeel
Copy link

in bootstrap-vue with browser i am not found it ?? !!
cdn : https://unpkg.com/bootstrap-vue@2.0.0-rc.11/dist/bootstrap-vue.js

@allaghi
Copy link

allaghi commented Feb 22, 2019

How about if you want to apply inline style on each row ? I want to style each row based on color comes from database ? any help ?

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

Successfully merging this pull request may close these issues.

Table: assign arbitrary CSS classes to rows