How do I create an HTML table with a fixed/frozen left column and a scrollable body?

后端 未结 25 1574
有刺的猬
有刺的猬 2020-11-21 22:27

I need a simple solution. I know it\'s similar to some other questions, like:

  • HTML table with fixed headers and a fixed column?
  • How can I lock the fir
25条回答
  •  悲哀的现实
    2020-11-21 23:11

    $(document).ready(function() {
        var table = $('#example').DataTable( {
            scrollY:        "400px",
            scrollX:        true,
            scrollCollapse: true,
            paging:         true,
            fixedColumns:   {
                leftColumns: 3
            }
        } );
    } );
    
    	table
    	
    
    
    
    
    
    
    
    
    
    
    
    
    First name Last name Position Office Age Start date Salary Extn. E-mail
    Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800 5421 t.nixon@datatables.net
    Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750 8422 g.winters@datatables.net
    Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000 1562 a.cox@datatables.net
    Cedric Kelly Senior Javascript Developer Edinburgh 22 2012/03/29 $433,060 6224 c.kelly@datatables.net
    Airi Satou Accountant Tokyo 33 2008/11/28 $162,700 5407 a.satou@datatables.net
    Brielle Williamson Integration Specialist New York 61 2012/12/02 $372,000 4804 b.williamson@datatables.net
    Herrod Chandler Sales Assistant San Francisco 59 2012/08/06 $137,500 9608 h.chandler@datatables.net
    Rhona Davidson Integration Specialist Tokyo 55 2010/10/14 $327,900 6200 r.davidson@datatables.net
    Colleen Hurst Javascript Developer San Francisco 39 2009/09/15 $205,500 2360 c.hurst@datatables.net
    Sonya Frost Software Engineer Edinburgh 23 2008/12/13 $103,600 1667 s.frost@datatables.net
    Jena Gaines Office Manager London 30 2008/12/19 $90,560 3814 j.gaines@datatables.net
    Sakura Yamamoto Support Engineer Tokyo 37 2009/08/19 $139,575 9383 s.yamamoto@datatables.net
    Thor Walton Developer New York 61 2013/08/11 $98,540 8327 t.walton@datatables.net
    Finn Camacho Support Engineer San Francisco 47 2009/07/07 $87,500 2927 f.camacho@datatables.net
    Serge Baldwin Data Coordinator Singapore 64 2012/04/09 $138,575 8352 s.baldwin@datatables.net
    Zenaida Frank Software Engineer New York 63 2010/01/04 $125,250 7439 z.frank@datatables.net
    Zorita Serrano Software Engineer San Francisco 56 2012/06/01 $115,000 4389 z.serrano@datatables.net
    Jennifer Acosta Junior Javascript Developer Edinburgh 43 2013/02/01 $75,650 3431 j.acosta@datatables.net
    Cara Stevens Sales Assistant New York 46 2011/12/06 $145,600 3990 c.stevens@datatables.net
    Hermione Butler Regional Director London 47 2011/03/21 $356,250 1016 h.butler@datatables.net
    Lael Greer Systems Administrator London 21 2009/02/27 $103,500 6733 l.greer@datatables.net
    Jonas Alexander Developer San Francisco 30 2010/07/14 $86,500 8196 j.alexander@datatables.net
    Shad Decker Regional Director Edinburgh 51 2008/11/13 $183,000 6373 s.decker@datatables.net
    Michael Bruce Javascript Developer Singapore 29 2011/06/27 $183,000 5384 m.bruce@datatables.net
    Donna Snider Customer Support New York 27 2011/01/25 $112,000 4226 d.snider@datatables.net

    This can be easily done with the help of datatables. People who are new to data tables, please refer to https://datatables.net/ .Its a plugin and offers a lot of features.In the the code given, header is fixed,first 3 columns are fixed and several other features are also there.

提交回复
热议问题