creating a table in ionic

后端 未结 9 1271
一向
一向 2021-01-31 03:27

I am in need of creating a table in Ionic. I thought of using Ionic grid but could not achieve what I wanted. How can I do this? Here is an image of something similar to what i

相关标签:
9条回答
  • 2021-01-31 03:45

    The flexbox grid should do what you want. You're not clear as to what limitation you ran into, so it's hard to address your specifics.

    Here's a codepen with a working sample that generates your table with the first couple rows and a header: http://codepen.io/anon/pen/pjzKMZ

    HTML

    <html ng-app="ionicApp">
    
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    
        <title>Ionic Template</title>
    
        <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
        <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
     </head>
    
      <body ng-controller="MyCtrl as ctrl">
        <ion-header-bar class="bar-stable">
            <h1 class="title">Service Provider Details</h1>
        </ion-header-bar>
        <ion-content>
            <div class="row header">
              <div class="col">Utility Company Name</div>
              <div class="col">Service Code</div>
              <div class="col">Pay Limit</div>
              <div class="col">Account Number to Use</div>
              <div class="col"></div>
            </div>
            <div class="row" ng-repeat="data in ctrl.data">
              <div class="col">{{data.name}}</div>
              <div class="col">{{data.code}}</div>
              <div class="col">LK {{data.limit}}</div>
              <div class="col">{{data.account}}</div>
              <div class="col"><button class="button" ng-click="ctrl.add($index)">Add</button></div>
            </div>
        </ion-content>
      </body>
    
    </html>
    

    CSS

    body {
        cursor: url('http://ionicframework.com/img/finger.png'), auto;
    }
    
    .header .col {
        background-color:lightgrey;
    }
    
    .col {
        border: solid 1px grey;
        border-bottom-style: none;
        border-right-style: none;
    }
    
    .col:last-child {
        border-right: solid 1px grey;
    }
    
    .row:last-child .col {
        border-bottom: solid 1px grey;
    }
    

    Javascript

    angular.module('ionicApp', ['ionic'])
    
    .controller('MyCtrl', function($scope) {
    
        var ctrl = this;
    
        ctrl.add = add;
        ctrl.data = [
            {
                name: "AiA",
                code: "AI101",
                limit: 25000,
                account: "Life Insurance"
            },
            {
                name: "Cargills",
                code: "CF001",
                limit: 30000,
                account: "Food City"
            }
        ]
    
        ////////
        function add(index) {
            window.alert("Added: " + index);
        }
    });
    
    0 讨论(0)
  • 2021-01-31 03:52

    .html file

    <ion-card-content>
    <div class='summary_row'>
          <div  class='summarycell'>Header 1</div>
          <div  class='summarycell'>Header 2</div>
          <div  class='summarycell'>Header 3</div>
          <div  class='summarycell'>Header 4</div>
          <div  class='summarycell'>Header 5</div>
          <div  class='summarycell'>Header 6</div>
          <div  class='summarycell'>Header 7</div>
    
        </div>
        <div  class='summary_row'>
          <div  class='summarycell'>
            Cell1
          </div>
          <div  class='summarycell'>
              Cell2
          </div>
            <div  class='summarycell'>
                Cell3
              </div>
    
          <div  class='summarycell'>
            Cell5
          </div>
          <div  class='summarycell'>
              Cell6
            </div>
            <div  class='summarycell'>
                Cell7
              </div>
              <div  class='summarycell'>
                  Cell8
                </div>
        </div>
    

    .scss file

    .row{
        display: flex;
        flex-wrap: wrap;
        width: max-content;
    }
    .row:first-child .summarycell{
        font-weight: bold;
        text-align: center;
    }
    .cell{
        overflow: auto;
        word-wrap: break-word;
        width: 27vw;
        border: 1px solid #b3b3b3;
        padding: 10px;
        text-align: right;
    }
    .cell:nth-child(2){
    }
    .cell:first-child{
        width:41vw;
        text-align: left;
    }

    0 讨论(0)
  • 2021-01-31 03:56

    In Ionic 2 there's a easier way to do that. See the Ionic Docs.

    It is more or less like the following:

    <ion-grid>
      <ion-row>
        <ion-col>
          1 of 3
        </ion-col>
        <ion-col>
          2 of 3
        </ion-col>
        <ion-col>
          3 of 3
        </ion-col>
      </ion-row>
    </ion-grid>
    
    0 讨论(0)
  • 2021-01-31 03:57

    This should probably be a comment, however, I don't have enough reputation to comment.

    I suggest you really use the table (HTML) instead of ion-row and ion-col. Things will not look nice when one of the cell's content is too long.

    One worse case looks like this:

    | 10 | 20 | 30 | 40 |
    | 1 | 2 | 3100 | 41 |
    

    Higher fidelity example fork from @jpoveda

    0 讨论(0)
  • 2021-01-31 03:57

    the issue of too long content @beenotung can be resolved by this css class :

    .col{
      max-width :20% !important;
    }
    

    example fork from @jpoveda

    0 讨论(0)
  • 2021-01-31 04:00

    Simply, for me, I used ion-row and ion-col to achieve it. You can make it more neater by doing some changes by CSS.

    <ion-row style="border-bottom: groove;">
          <ion-col col-4>
          <ion-label >header</ion-label>
        </ion-col>
        <ion-col col-4>
          <ion-label >header</ion-label>
        </ion-col>
          <ion-col col-4>
          <ion-label >header</ion-label>
        </ion-col>
      </ion-row>
      <ion-row style="border-bottom: groove;">
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
        <ion-col col-4>
          <ion-label >02/02/2018</ion-label>
        </ion-col>
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
      </ion-row>
      <ion-row style="border-bottom: groove;">
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
        <ion-col col-4>
          <ion-label >02/02/2018</ion-label>
        </ion-col>
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
      </ion-row>
      <ion-row >
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
        <ion-col col-4>
          <ion-label >02/02/2018</ion-label>
        </ion-col>
          <ion-col col-4>
          <ion-label >row</ion-label>
        </ion-col>
      </ion-row>
    
    0 讨论(0)
提交回复
热议问题