There are some solutions to display the alternate items.
1. Use the 'labelFormatter' and 'formatter' functions.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TimeLine - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-panel" style="padding:10px;">
<div id="tt"></div>
</div>
<script>
var data = [
{ content: 'Goal', contentPosition: 'before', time: '10:30', playerName: 'Player #1', info: '' },
{ content: 'Penalty', contentPosition: 'after', time: '12:00', playerName: 'Player #2', info: 'Yellow Card' },
{ content: 'Goal', contentPosition: 'before', time: '14:30', playerName: 'Player #3', info: '' },
{ content: 'Goal', contentPosition: 'after', time: '16:30', playerName: 'Player #4', info: '' }
]
$(function () {
const formatContent = (row) => {
return `
<div>
<div style="font-size:14px;font-weight:bold">${row.time} - ${row.content}</div>
<div style="font-size:12px;color:#666">${row.playerName}</div>
<div style="font-size:12px;color:#666">${row.info}</div>
</div>
`
}
$('#tt').timeline({
data: data,
formatter: (row) => {
if (row.contentPosition == 'after') {
return formatContent(row)
} else {
return '<div style="height:45px"></div>';
}
},
labelFormatter: (row) => {
if (row.contentPosition == 'before') {
return formatContent(row)
} else {
return '';
}
}
})
})
</script>
</body>
</html>
2. Set the 'align' property value to 'alternateReverse'.
const formatContent = (row) => {
return `
<div>
<div style="font-size:14px;font-weight:bold">${row.time} - ${row.content}</div>
<div style="font-size:12px;color:#666">${row.playerName}</div>
<div style="font-size:12px;color:#666">${row.info}</div>
</div>
`
}
$('#tt').timeline({
data: data,
align: 'alternateReverse',
formatter: formatContent
})
3. Custom the 'itemPosition' function to set the item position to 'left' or 'right'.
const formatContent = (row) => {
return `
<div>
<div style="font-size:14px;font-weight:bold">${row.time} - ${row.content}</div>
<div style="font-size:12px;color:#666">${row.playerName}</div>
<div style="font-size:12px;color:#666">${row.info}</div>
</div>
`
}
$('#tt').timeline({
data: data,
align: 'alternate',
formatter: formatContent,
itemPosition: (row,index) => {
return row.contentPosition=='after' ? 'left' : 'right';
}
})