Skip to content
Snippets Groups Projects
Commit 854403cb authored by Phil Hughes's avatar Phil Hughes
Browse files

Added line linking on each worksheet

Former-commit-id: 79aed1ea
parent 6ff9ed25
No related branches found
No related tags found
No related merge requests found
import 'vendor/jquery.scrollTo';
export default {
name: 'XLSXTable',
props: {
Loading
Loading
@@ -6,29 +8,77 @@ export default {
required: true,
},
},
data() {
return {
currentLineNumber: -1,
};
},
methods: {
linePath(index) {
let hash = location.hash.replace('#', '');
hash = hash.replace(/-?L(\d+)$/g, '');
if (hash !== '') {
return `#${hash}-L${index + 1}`;
} else {
return `#L${index + 1}`;
}
},
updateCurrentLineNumber(index) {
this.currentLineNumber = index + 1;
},
getCurrentLineNumberFromUrl() {
const hash = location.hash.replace('#', '').split('-');
const lineHash = hash[hash.length - 1];
this.currentLineNumber = parseInt(lineHash.replace('L', ''), 10);
},
},
watch: {
sheet: {
handler() {
this.getCurrentLineNumberFromUrl();
},
deep: true,
}
},
created() {
this.getCurrentLineNumberFromUrl();
},
mounted() {
$.scrollTo(`#${this.currentLineNumber}`);
},
template: `
<table
class="table">
<thead>
<tr>
<th></th>
<th
v-for="name in sheet.columns">
{{ name }}
</th>
</tr>
</thead>
<tbody>
<tr
v-for="(row, index) in sheet.rows">
<th>
{{ index + 1 }}
</th>
<td v-for="val in row">
{{ val }}
</td>
</tr>
</tbody>
</table>
<div class="table-responsive">
<table
class="table">
<thead>
<tr>
<th></th>
<th
v-for="name in sheet.columns">
{{ name }}
</th>
</tr>
</thead>
<tbody>
<tr
v-for="(row, index) in sheet.rows"
:id="index + 1"
:class="{ hll: currentLineNumber === index + 1 }">
<td>
<a
:href="linePath(index)"
@click="updateCurrentLineNumber(index)">
{{ index + 1 }}
</a>
</td>
<td v-for="val in row">
{{ val }}
</td>
</tr>
</tbody>
</table>
</div>
`,
};
Loading
Loading
@@ -28,7 +28,10 @@ export default {
},
methods: {
getInitialSheet() {
return decodeURIComponent(location.hash.replace('#', '')) || this.sheetNames[0];
let hash = location.hash.split('-');
hash = decodeURIComponent(hash[0].replace('#', ''));
return this.sheetNames.find(sheet => sheet === hash) || this.sheetNames[0];
},
},
created() {
Loading
Loading
.hll {
> td {
background-color: #f8eec7;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment