TheCoder4eu / BootsFaces-OSP

BootsFaces - Open Source Project
Apache License 2.0
246 stars 102 forks source link

Please help me: How to get datatable row index? #910

Closed tamtc84 closed 6 years ago

tamtc84 commented 6 years ago

I use Bootsfaces 1.2.0: `

</b:dataTableColumn>` I want to view index column in "Row number" column. I saw it in https://datatables.net/examples/api/counter_columns.html But i don't know how to use in . Please help me to do it. Thank you.

stephanrauh commented 6 years ago

The example on the DataTable.net page uses some fancy JavaScript. I'm reluctant to include something like this in BootsFaces. The idea of JSF is to provide a simple, easy-to-grasp abstraction between you and the HTML5 page. If you need more power, JSF enables you to use HTML5 directly.

So I suggest you look for a simpler approach. For example, you could add the row index to the elements of the array in the backing bean. Is that an option to you?

stephanrauh commented 6 years ago

Any news on this? I'll close this ticket because I didn't hear from you. IMHO, the approach using the JSF bean should do the trick, so there's a workaround (even if it may be less elegant than the approach shown at the DataTables.net documentation).

vsvetoslavov commented 6 years ago

Usually a status var (similar to the var attribute) would fit th case. Tomahawk and PrimeFaces I think have such attribute in their datatables. So I guess this could be a sort of a feature suggestion, @stephanrauh ... :) I think also I saw somewhere (in stackoverflow I guess) a suggestion to use indexOf(row) if the collection supports it (i.e. List).

gmanjon commented 3 years ago

Hello everyone,

I know is a bit late for this, but I thought of a workaround worth sharing. In the case exposed here would be the following:

<b:dataTable value="#{aBean.getDataList()}" var="item">
    <b:dataTableColumn label="Row number">
        <h:outputText value="#{aBean.getDataList().indexOf(item) + 1}" />
    </b:dataTableColumn>
    ... 

That would render the index of the element in the list.

I really think the index feature is something worth adding, I've always seen it in every data table helper library I've come across with. Anyhow thanks to the authors of Bootsfaces for this great library :D