Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div class="container">

  <div class="page-header">
    <h1>An Editable Grid with jQuery, Bootstrap, and Shield UI Lite</h1>
  </div>

  <!-- Editable Grid - START -->

  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="text-center">Click inside any of the content cells to edit the grid.<span class="fa fa-edit pull-right bigicon"></span></h4>
      </div>
      <div class="panel-body text-center">
        <div id="grid"></div>
      </div>
    </div>
  </div>
</div>

<p class="p">Demo by David Johnson. <a href="http://www.sitepoint.com/editable-grid-jquery-bootstrap-shield-ui-lite" target="_blank">See article</a>.</p>
              
            
!

CSS

              
                h1, th {
  text-align: center;
}

.sui-gridheader .sui-headercell {
  text-align: center;
}

.sui-grid-core {
  font-family: Arial, sans-serif;
}

.sui-button-cell {
  text-align: center;
}

.sui-checkbox {
  font-size: 17px !important;
  padding-bottom: 4px !important;
}

.deleteButton img {
  margin-right: 3px;
  vertical-align: bottom;
}

.bigicon {
  color: #5CB85C;
  font-size: 20px;
}

.p {
  text-align: center;
}
              
            
!

JS

              
                $(document).ready(function() {
  $("#grid").shieldGrid({
    dataSource: {
      data: gridData,
      schema: {
        fields: {
          id: {
            path: "id",
            type: Number
          },
          age: {
            path: "age",
            type: Number
          },
          name: {
            path: "name",
            type: String
          },
          company: {
            path: "company",
            type: String
          },
          month: {
            path: "month",
            type: Date
          },
          isActive: {
            path: "isActive",
            type: Boolean
          },
          email: {
            path: "email",
            type: String
          },
          transport: {
            path: "transport",
            type: String
          }
        }
      }
    },
    rowHover: false,
    columns: [{
      field: "name",
      title: "Person Name",
      width: "120px"
    }, {
      field: "age",
      title: "Age",
      width: "80px"
    }, {
      field: "company",
      title: "Company Name"
    }, {
      field: "month",
      title: "Date of Birth",
      format: "{0:MM/dd/yyyy}",
      width: "120px"
    }, {
      field: "isActive",
      title: "Active"
    }, {
      field: "email",
      title: "Email Address",
      width: "250px"
    }, {
      field: "transport",
      title: "Custom Editor",
      width: "120px",
      editor: myCustomEditor
    }, {
      width: "104px",
      title: "Delete Row",
      buttons: [{
        cls: "deleteButton",
        commandName: "delete",
        caption: "<img src='https://www.prepbootstrap.com/Content/images/template/BootstrapEditableGrid/delete.png' /><span>Delete</span>"
      }]
    }],
    editing: {
      enabled: true,
      event: "click",
      type: "cell",
      confirmation: {
        "delete": {
          enabled: true,
          template: function(item) {
            return "Delete row with ID = " + item.id
          }
        }
      }
    },
    events: {
      getCustomEditorValue: function(e) {
        e.value = $("#dropdown").swidget().value();
        $("#dropdown").swidget().destroy();
      }
    }
  });

  function myCustomEditor(cell, item) {
    $('<div id="dropdown"/>')
      .appendTo(cell)
      .shieldDropDown({
        dataSource: {
          data: ["motorbike", "car", "truck"]
        },
        value: !item["transport"] ? null : item["transport"].toString()
      }).swidget().focus();
  }
});
              
            
!
999px

Console