Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <script type="text/x-template" id="grid-template">
<table>
	<thead>
		<tr>
			<th v-for="key in columns"
				@click="sortBy(key)"
				:class="{active: sortKey === key}">
				{{key | capitalize}}
				<span class="arrow" :class="sortOrders[key] > 0 ? 'asc' : 'dsc'">
				</span>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr v-for="entry in filteredData">
			<td v-for="key in columns">
				{{entry[key]}}
			</td>
		</tr>
	</tbody>
</table>
</script>

<div id="demo">
	<form id="search">
		Search <input name="query" v-model="searchQuery">
	</form>
	<demo-grid
		:data="gridData"
		:columns="gridColumns"
		:filter-key="searchQuery">
	</demo-grid>
</div>

              
            
!

CSS

              
                body {
	font-family: Helvetica Neue, Arial, sans-serif;
	font-size: 14px;
	color: #444;
}
table {
	border: 2px solid #42b983;
	border-radius: 3px;
	background-color: #fff;
}
th {
	background-color: #42b983;
	color: rgba(255,255,255,0.66);
	cursor: pointer;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}
td {
	background-color: #f9f9f9;
}
th, td {
	min-width: 120px;
	padding: 10px 20px;
}
th.active {
	color: #fff;
}
th.active .arrow {
	opacity: 1;
}
.arrow {
	display: inline-block;
	vertical-align: middle;
	width: 0;
	height: 0;
	margin-left: 5px;
	opacity: 0.66;
}
.arrow.asc {
	border-left: 4px solid transparent;
	border-right: 4px solid transparent;
	border-bottom: 4px solid #fff;
}
.arrow.dsc {
	border-left: 4px solid transparent;
	border-right: 4px solid transparent;
	border-top: 4px solid #fff;
}

              
            
!

JS

              
                Vue.component('demo-grid', {
	template: '#grid-template',
	props: {
		data: Array,
		columns: Array,
		filterKey: String
	},
	data() {
		const sortOrders = {};
		this.columns.forEach((key) => sortOrders[key] = 1);
		return {
			sortKey: '',
			sortOrders: sortOrders
		};
	},
	computed: {
		filteredData() {
			const sortKey = this.sortKey;
			const filterKey = this.filterKey && this.filterKey.toLowerCase();
			const order = this.sortOrders[sortKey] || 1;
			let data = this.data;
			if (filterKey) {
				data = data.filter((row) =>
					Object.keys(row).some((key) =>
						String(row[key]).toLowerCase().includes(filterKey)
					)
				);
			}
			if(sortKey) {
				data = data.slice().sort((a, b) => {
					a = a[sortKey];
					b = b[sortKey];
					return (a === b ? 0 : a > b ? 1 : -1) * order;
				});
			}
			return data;
		}
	},
	filters: {
		capitalize(str) {
			return str.charAt(0).toUpperCase() + str.slice(1);
		}
	},
	methods: {
		sortBy(key) {
			this.sortKey = key;
			this.sortOrders[key] *= -1;
		}
	}
});
const demo = new Vue({
	data: {
		searchQuery: '',
		gridColumns: ['name', 'power'],
		gridData: [
			{name: 'Chuck Norris', power: Infinity},
			{name: 'Bruce Lee', power: 9000},
			{name: 'Jackie Chan', power: 7000},
			{name: 'Jet Li', power: 8000}
		]
	}
});
document.addEventListener('DOMContentLoaded', (event) =>
	demo.$mount('#demo')
);

              
            
!
999px

Console