0

i'm using this answer to fixed my first columns inside bootstrap table.

i want to make the first TWO columns fixed, what do i need to change on the code?

Community
  • 1
  • 1
user2587454
  • 903
  • 1
  • 19
  • 44

4 Answers4

0

Change this line $fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();

to your desired column with :nth-child() Selector

 $fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();`
`$fixedColumn.find('th:not(:nth-child(2)),td:not(:nth-child(2))').remove();`
Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43
0

Change this line $fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();

to your desired column with :nth-child() Selector

$fixedColumn.find('th:not(:nth-child(-n+2)),td:not(:nth-child(-n+2))').remove();
young
  • 1
0

Change the line

$fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();

With

$fixedColumn.find('th:not(:first-child,:nth-child(2)),td:not(:first-child,:nth-child(2)').remove();

Notice that you can keep adding up columns as you please

user3062906
  • 23
  • 1
  • 5
0

You can set a class for pin n columns as you prefer:

var $table = $('.table-pinned');
var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');

$fixedColumn.find('th,td').not('.pinned').remove();

$fixedColumn.find('tr').each(function (i, elem) {
  $(this).height($table.find('tr:eq(' + i + ')').height());
});

Here fiddle

Lughino
  • 4,060
  • 11
  • 31
  • 61