DontPlanToEnd
commited on
Create assets/dashAgGridComponentFunctions.js
Browse files
assets/dashAgGridComponentFunctions.js
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
|
2 |
+
// Store original data globally
|
3 |
+
window.gridOriginalData = null;
|
4 |
+
|
5 |
+
dagcomponentfuncs.ModelLink = function(props) {
|
6 |
+
if (!props.data.Model_Link) {
|
7 |
+
return props.value; // Just return text if no link
|
8 |
+
}
|
9 |
+
return React.createElement(
|
10 |
+
'a',
|
11 |
+
{
|
12 |
+
href: props.data.Model_Link,
|
13 |
+
target: '_blank',
|
14 |
+
style: {
|
15 |
+
color: '#007bff',
|
16 |
+
textDecoration: 'none'
|
17 |
+
}
|
18 |
+
},
|
19 |
+
props.value
|
20 |
+
);
|
21 |
+
};
|
22 |
+
|
23 |
+
dagcomponentfuncs.PinRenderer = function(props) {
|
24 |
+
// Store original data when component first renders
|
25 |
+
if (!window.gridOriginalData) {
|
26 |
+
const allRows = [];
|
27 |
+
props.api.forEachNode(node => {
|
28 |
+
allRows.push({...node.data});
|
29 |
+
});
|
30 |
+
window.gridOriginalData = allRows;
|
31 |
+
}
|
32 |
+
|
33 |
+
return React.createElement(
|
34 |
+
'div',
|
35 |
+
{
|
36 |
+
onClick: function() {
|
37 |
+
const api = props.api;
|
38 |
+
const newValue = !props.value;
|
39 |
+
|
40 |
+
// Create a copy of the original data and update pin state for clicked row only
|
41 |
+
const allRows = window.gridOriginalData.map(row => ({
|
42 |
+
...row,
|
43 |
+
// Preserve existing pin states and only update the clicked row
|
44 |
+
pinned: row.Model_Display === props.data.Model_Display ? newValue :
|
45 |
+
(row.pinned || false)
|
46 |
+
}));
|
47 |
+
|
48 |
+
// Update window.gridOriginalData to maintain pin states
|
49 |
+
window.gridOriginalData = allRows;
|
50 |
+
|
51 |
+
// Separate rows
|
52 |
+
const pinnedRows = allRows.filter(row => row.pinned);
|
53 |
+
const unpinnedRows = allRows.filter(row => !row.pinned);
|
54 |
+
|
55 |
+
// Update both sections
|
56 |
+
api.setPinnedTopRowData(pinnedRows);
|
57 |
+
api.setRowData(unpinnedRows);
|
58 |
+
},
|
59 |
+
style: {
|
60 |
+
cursor: 'pointer',
|
61 |
+
textAlign: 'center',
|
62 |
+
fontSize: '16px'
|
63 |
+
}
|
64 |
+
},
|
65 |
+
props.value ? '📌' : '☐'
|
66 |
+
);
|
67 |
+
};
|