@@ -638,6 +638,7 @@ define([
638
638
639
639
FrameEditor . prototype . renderRenamePage = function ( ) {
640
640
var content = new sb . StringBuilder ( ) ;
641
+ content . appendFormatLine ( '<div class="{0} {1}">' , 'vp-popup-rename-page' , 'vp-scrollbar' ) ;
641
642
content . appendLine ( '<table>' ) ;
642
643
content . appendLine ( '<colgroup><col width="100px"><col width="*"></colgroup>' ) ;
643
644
this . state . selected . forEach ( ( col , idx ) => {
@@ -648,17 +649,20 @@ define([
648
649
content . appendLine ( '</tr>' ) ;
649
650
} ) ;
650
651
content . appendLine ( '</table>' ) ;
652
+ content . appendLine ( '</div>' ) ;
651
653
return content . toString ( ) ;
652
654
}
653
655
654
656
FrameEditor . prototype . renderReplacePage = function ( ) {
655
657
var content = new sb . StringBuilder ( ) ;
656
658
content . appendFormatLine ( '<label><input type="checkbox" class="{0}"/><span>{1}</span></label>' , 'vp-popup-use-regex' , 'Use Regular Expression' ) ;
657
659
content . appendLine ( '<br/><br/>' ) ;
658
- content . appendFormatLine ( '<table class="{0}">' , 'vp-popup-replace-table' ) ;
660
+ content . appendFormatLine ( '<div class="{0}">' , 'vp-popup-replace-table' ) ;
661
+ content . appendLine ( '<table>' ) ;
659
662
content . appendLine ( this . renderReplaceInput ( 0 ) ) ;
660
663
content . appendFormatLine ( '<tr><td colspan="3"><button class="{0} {1}">{2}</button></td></tr>' , 'vp-button' , 'vp-popup-replace-add' , '+ Add Key' ) ;
661
664
content . appendLine ( '</table>' ) ;
665
+ content . appendLine ( '</div>' ) ;
662
666
return content . toString ( ) ;
663
667
}
664
668
@@ -1170,18 +1174,24 @@ define([
1170
1174
return code . toString ( ) ;
1171
1175
}
1172
1176
1173
- FrameEditor . prototype . loadCode = function ( codeStr ) {
1177
+ FrameEditor . prototype . loadCode = function ( codeStr , more = false ) {
1174
1178
if ( this . loading ) {
1175
1179
return ;
1176
1180
}
1177
1181
1178
1182
var that = this ;
1179
1183
var tempObj = this . state . tempObj ;
1180
1184
var lines = this . state . lines ;
1185
+ var prevLines = 0 ;
1186
+ var scrollPos = - 1 ;
1187
+ if ( more ) {
1188
+ prevLines = that . state . indexList . length ;
1189
+ scrollPos = $ ( this . wrapSelector ( '.vp-fe-table' ) ) . scrollTop ( ) ;
1190
+ }
1181
1191
1182
1192
var code = new sb . StringBuilder ( ) ;
1183
1193
code . appendLine ( codeStr ) ;
1184
- code . appendFormat ( "{0}.head( {1}) .to_json(orient='{2 }')" , tempObj , lines , 'split' ) ;
1194
+ code . appendFormat ( "{0}[ {1}:{2}] .to_json(orient='{3 }')" , tempObj , prevLines , lines , 'split' ) ;
1185
1195
1186
1196
this . loading = true ;
1187
1197
kernelApi . executePython ( code . toString ( ) , function ( result ) {
@@ -1193,62 +1203,101 @@ define([
1193
1203
// var columnList = data.columns;
1194
1204
var indexList = data . index ;
1195
1205
var dataList = data . data ;
1206
+
1207
+ columnList = columnList . map ( col => { return { label : col . label , type : col . dtype , code : col . value } } ) ;
1208
+ indexList = indexList . map ( idx => { return { label : idx , code : idx } } ) ;
1196
1209
1197
- that . state . columnList = columnList . map ( col => { return { label : col . label , type : col . dtype , code : col . value } } ) ;
1198
- that . state . indexList = indexList . map ( idx => { return { label : idx , code : idx } } ) ;
1199
-
1200
- // table
1201
- var table = new sb . StringBuilder ( ) ;
1202
- // table.appendFormatLine('<table border="{0}" class="{1}">', 1, 'dataframe');
1203
- table . appendLine ( '<thead>' ) ;
1204
- table . appendLine ( '<tr><th></th>' ) ;
1205
- that . state . columnList && that . state . columnList . forEach ( col => {
1206
- var colCode = col . code ;
1207
- var colClass = '' ;
1208
- if ( that . state . axis == FRAME_AXIS . COLUMN && that . state . selected . map ( col => col . code ) . includes ( colCode ) ) {
1209
- colClass = 'selected' ;
1210
- }
1211
- table . appendFormatLine ( '<th data-code="{0}" data-axis="{1}" data-type="{2}" class="{3} {4}">{5}</th>'
1212
- , colCode , FRAME_AXIS . COLUMN , col . type , VP_FE_TABLE_COLUMN , colClass , col . label ) ;
1213
- } ) ;
1214
- // add column
1215
- table . appendFormatLine ( '<th class="{0}"><img src="{1}"/></th>' , VP_FE_ADD_COLUMN , '/nbextensions/visualpython/resource/plus.svg' ) ;
1216
-
1217
- table . appendLine ( '</tr>' ) ;
1218
- table . appendLine ( '</thead>' ) ;
1219
- table . appendLine ( '<tbody>' ) ;
1220
-
1221
- dataList && dataList . forEach ( ( row , idx ) => {
1222
- table . appendLine ( '<tr>' ) ;
1223
- var idxName = that . state . indexList [ idx ] . label ;
1224
- var idxLabel = convertToStr ( idxName , typeof idxName == 'string' ) ;
1225
- var idxClass = '' ;
1226
- if ( that . state . axis == FRAME_AXIS . ROW && that . state . selected . includes ( idxLabel ) ) {
1227
- idxClass = 'selected' ;
1228
- }
1229
- table . appendFormatLine ( '<th data-code="{0}" data-axis="{1}" class="{2} {3}">{4}</th>' , idxLabel , FRAME_AXIS . ROW , VP_FE_TABLE_ROW , idxClass , idxName ) ;
1230
- row . forEach ( ( cell , colIdx ) => {
1231
- if ( cell == null ) {
1232
- cell = 'NaN' ;
1210
+ if ( ! more ) {
1211
+ // table
1212
+ var table = new sb . StringBuilder ( ) ;
1213
+ // table.appendFormatLine('<table border="{0}" class="{1}">', 1, 'dataframe');
1214
+ table . appendLine ( '<thead>' ) ;
1215
+ table . appendLine ( '<tr><th></th>' ) ;
1216
+ columnList && columnList . forEach ( col => {
1217
+ var colCode = col . code ;
1218
+ var colClass = '' ;
1219
+ if ( that . state . axis == FRAME_AXIS . COLUMN && that . state . selected . map ( col => col . code ) . includes ( colCode ) ) {
1220
+ colClass = 'selected' ;
1233
1221
}
1234
- var cellType = that . state . columnList [ colIdx ] . type ;
1235
- if ( cellType . includes ( 'datetime' ) ) {
1236
- cell = new Date ( parseInt ( cell ) ) . toLocaleDateString ( ) ;
1222
+ table . appendFormatLine ( '<th data-code="{0}" data-axis="{1}" data-type="{2}" class="{3} {4}">{5}</th>'
1223
+ , colCode , FRAME_AXIS . COLUMN , col . type , VP_FE_TABLE_COLUMN , colClass , col . label ) ;
1224
+ } ) ;
1225
+ // add column
1226
+ table . appendFormatLine ( '<th class="{0}"><img src="{1}"/></th>' , VP_FE_ADD_COLUMN , '/nbextensions/visualpython/resource/plus.svg' ) ;
1227
+
1228
+ table . appendLine ( '</tr>' ) ;
1229
+ table . appendLine ( '</thead>' ) ;
1230
+ table . appendLine ( '<tbody>' ) ;
1231
+
1232
+ dataList && dataList . forEach ( ( row , idx ) => {
1233
+ table . appendLine ( '<tr>' ) ;
1234
+ var idxName = indexList [ idx ] . label ;
1235
+ var idxLabel = convertToStr ( idxName , typeof idxName == 'string' ) ;
1236
+ var idxClass = '' ;
1237
+ if ( that . state . axis == FRAME_AXIS . ROW && that . state . selected . includes ( idxLabel ) ) {
1238
+ idxClass = 'selected' ;
1237
1239
}
1238
- table . appendFormatLine ( '<td>{0}</td>' , cell ) ;
1240
+ table . appendFormatLine ( '<th data-code="{0}" data-axis="{1}" class="{2} {3}">{4}</th>' , idxLabel , FRAME_AXIS . ROW , VP_FE_TABLE_ROW , idxClass , idxName ) ;
1241
+ row . forEach ( ( cell , colIdx ) => {
1242
+ if ( cell == null ) {
1243
+ cell = 'NaN' ;
1244
+ }
1245
+ var cellType = columnList [ colIdx ] . type ;
1246
+ if ( cellType . includes ( 'datetime' ) ) {
1247
+ cell = new Date ( parseInt ( cell ) ) . toLocaleString ( ) ;
1248
+ }
1249
+ table . appendFormatLine ( '<td>{0}</td>' , cell ) ;
1250
+ } ) ;
1251
+ // empty data
1252
+ // table.appendLine('<td></td>');
1253
+ table . appendLine ( '</tr>' ) ;
1239
1254
} ) ;
1240
- // empty data
1241
- // table.appendLine('<td></td>');
1255
+ // add row
1256
+ table . appendLine ( '<tr>' ) ;
1257
+ table . appendFormatLine ( '<th class="{0}"><img src="{1}"/></th>' , VP_FE_ADD_ROW , '/nbextensions/visualpython/resource/plus.svg' ) ;
1242
1258
table . appendLine ( '</tr>' ) ;
1243
- } ) ;
1244
- // add row
1245
- table . appendLine ( '<tr>' ) ;
1246
- table . appendFormatLine ( '<th class="{0}"><img src="{1}"/></th>' , VP_FE_ADD_ROW , '/nbextensions/visualpython/resource/plus.svg' ) ;
1247
- table . appendLine ( '</tbody>' ) ;
1248
- table . appendLine ( '</tr>' ) ;
1249
- $ ( that . wrapSelector ( '.' + VP_FE_TABLE ) ) . replaceWith ( function ( ) {
1250
- return that . renderTable ( table . toString ( ) ) ;
1251
- } ) ;
1259
+ table . appendLine ( '</tbody>' ) ;
1260
+ $ ( that . wrapSelector ( '.' + VP_FE_TABLE ) ) . replaceWith ( function ( ) {
1261
+ return that . renderTable ( table . toString ( ) ) ;
1262
+ } ) ;
1263
+ } else {
1264
+ var table = new sb . StringBuilder ( ) ;
1265
+ dataList && dataList . forEach ( ( row , idx ) => {
1266
+ table . appendLine ( '<tr>' ) ;
1267
+ var idxName = indexList [ idx ] . label ;
1268
+ var idxLabel = convertToStr ( idxName , typeof idxName == 'string' ) ;
1269
+ var idxClass = '' ;
1270
+ if ( that . state . axis == FRAME_AXIS . ROW && that . state . selected . includes ( idxLabel ) ) {
1271
+ idxClass = 'selected' ;
1272
+ }
1273
+ table . appendFormatLine ( '<th data-code="{0}" data-axis="{1}" class="{2} {3}">{4}</th>' , idxLabel , FRAME_AXIS . ROW , VP_FE_TABLE_ROW , idxClass , idxName ) ;
1274
+ row . forEach ( ( cell , colIdx ) => {
1275
+ if ( cell == null ) {
1276
+ cell = 'NaN' ;
1277
+ }
1278
+ var cellType = columnList [ colIdx ] . type ;
1279
+ if ( cellType . includes ( 'datetime' ) ) {
1280
+ cell = new Date ( parseInt ( cell ) ) . toLocaleString ( ) ;
1281
+ }
1282
+ table . appendFormatLine ( '<td>{0}</td>' , cell ) ;
1283
+ } ) ;
1284
+ // empty data
1285
+ // table.appendLine('<td></td>');
1286
+ table . appendLine ( '</tr>' ) ;
1287
+ } ) ;
1288
+ // insert before last tr tag(add row button)
1289
+ $ ( table . toString ( ) ) . insertBefore ( $ ( that . wrapSelector ( '.' + VP_FE_TABLE + ' tbody tr:last' ) ) ) ;
1290
+ }
1291
+
1292
+ // save columnList & indexList as state
1293
+ that . state . columnList = columnList ;
1294
+ if ( ! more ) {
1295
+ that . state . indexList = indexList ;
1296
+ } else {
1297
+ that . state . indexList = that . state . indexList . concat ( indexList ) ;
1298
+ }
1299
+
1300
+
1252
1301
// load info
1253
1302
that . loadInfo ( ) ;
1254
1303
// add to stack
@@ -1257,6 +1306,11 @@ define([
1257
1306
var replacedCode = codeStr . replaceAll ( that . state . tempObj , that . state . returnObj ) ;
1258
1307
that . setPreview ( replacedCode ) ;
1259
1308
}
1309
+
1310
+ // if scrollPos is saved, go to the position
1311
+ if ( scrollPos >= 0 ) {
1312
+ $ ( that . wrapSelector ( '.vp-fe-table' ) ) . scrollTop ( scrollPos ) ;
1313
+ }
1260
1314
1261
1315
that . loading = false ;
1262
1316
} ) ;
@@ -1592,7 +1646,7 @@ define([
1592
1646
// more rows
1593
1647
$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE_MORE ) , function ( ) {
1594
1648
that . state . lines += TABLE_LINES ;
1595
- that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . SHOW ) ) ;
1649
+ that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . SHOW ) , true ) ;
1596
1650
} ) ;
1597
1651
1598
1652
// click toolbar item
0 commit comments