Knockout with dateString
Applies binding with dateString formatting on date times.
by Dejan Vasic
HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<div id="input">
<input type="text" placeholder="New Task" id="txtTaskName" />
<a id="addItem" href="#" class="button small">Add</a>
</div>
<div id="output">
<table>
<thead>
<tr>
<th>Task</th>
<th>Due</th>
</tr>
<thead>
<tbody data-bind="foreach: Tasks">
<tr>
<td data-bind="text: Title"></td>
<td data-bind="text: DueDate"></td>
</tr>
</tbody>
</table>
</div>
CSS
table a:link {
color: #666;
font-weight: bold;
text-decoration:none;
}
table a:visited {
color: #999999;
font-weight:bold;
text-decoration:none;
}
table a:active, table a:hover {
color: #bd5a35;
text-decoration:underline;
}
table {
font-family:Arial, Helvetica, sans-serif;
color:#666;
font-size:12px;
text-shadow: 1px 1px 0px #fff;
background:#eaebec;
margin:20px;
border:#ccc 1px solid;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
-moz-box-shadow: 0 1px 2px #d1d1d1;
-webkit-box-shadow: 0 1px 2px #d1d1d1;
box-shadow: 0 1px 2px #d1d1d1;
}
table th {
padding:21px 25px 22px 25px;
border-top:1px solid #fafafa;
border-bottom:1px solid #e0e0e0;
background: #ededed;
background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#ebebeb));
background: -moz-linear-gradient(top, #ededed, #ebebeb);
}
table th:first-child {
text-align: left;
padding-left:20px;
}
table tr:first-child th:first-child {
-moz-border-radius-topleft:3px;
-webkit-border-top-left-radius:3px;
border-top-left-radius:3px;
}
table tr:first-child th:last-child {
-moz-border-radius-topright:3px;
-webkit-border-top-right-radius:3px;
border-top-right-radius:3px;
}
table tr {
text-align: center;
padding-left:20px;
}
table td:first-child {
text-align: left;
padding-left:20px;
border-left: 0;
}
table td {
padding:18px;
border-top: 1px solid #ffffff;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
background: #fafafa;
background: -webkit-gradient(linear, left top, left bottom, from(#fbfbfb), to(#fafafa));
background: -moz-linear-gradient(top, #fbfbfb, #fafafa);
}
table tr.even td {
background: #f6f6f6;
background: -webkit-gradient(linear, left top, left bottom, from(#f8f8f8), to(#f6f6f6));
background: -moz-linear-gradient(top, #f8f8f8, #f6f6f6);
}
table...
JavaScript
Model = function () {
this.Tasks = ko.observableArray([{
Title: 'Add dates to the patient data selection page',
DueDate: '26-06-2013'
}]);
};
var testModel = new Model();
ko.applyBindings(testModel);
$().ready(function () {
$('#addItem').on('click', function () {
var newItem = {
Title: $('#txtTaskName').val(),
DueDate: '26-06-2013'
};
testModel.Tasks.push(newItem);
});
$('#').on('focus', function(){
});
});