@@ -638,6 +638,7 @@ define([
638638
639639FrameEditor . prototype . renderRenamePage = function ( ) {
640640var content = new sb . StringBuilder ( ) ;
641+ content . appendFormatLine ( '<div class="{0} {1}">' , 'vp-popup-rename-page' , 'vp-scrollbar' ) ;
641642content . appendLine ( '<table>' ) ;
642643content . appendLine ( '<colgroup><col width="100px"><col width="*"></colgroup>' ) ;
643644this . state . selected . forEach ( ( col , idx ) => {
@@ -648,17 +649,20 @@ define([
648649content . appendLine ( '</tr>' ) ;
649650} ) ;
650651content . appendLine ( '</table>' ) ;
652+ content . appendLine ( '</div>' ) ;
651653return content . toString ( ) ;
652654}
653655
654656FrameEditor . prototype . renderReplacePage = function ( ) {
655657var content = new sb . StringBuilder ( ) ;
656658content . appendFormatLine ( '<label><input type="checkbox" class="{0}"/><span>{1}</span></label>' , 'vp-popup-use-regex' , 'Use Regular Expression' ) ;
657659content . 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>' ) ;
659662content . appendLine ( this . renderReplaceInput ( 0 ) ) ;
660663content . appendFormatLine ( '<tr><td colspan="3"><button class="{0} {1}">{2}</button></td></tr>' , 'vp-button' , 'vp-popup-replace-add' , '+ Add Key' ) ;
661664content . appendLine ( '</table>' ) ;
665+ content . appendLine ( '</div>' ) ;
662666return content . toString ( ) ;
663667}
664668
@@ -1170,18 +1174,24 @@ define([
11701174return code . toString ( ) ;
11711175}
11721176
1173- FrameEditor . prototype . loadCode = function ( codeStr ) {
1177+ FrameEditor . prototype . loadCode = function ( codeStr , more = false ) {
11741178if ( this . loading ) {
11751179return ;
11761180}
11771181
11781182var that = this ;
11791183var tempObj = this . state . tempObj ;
11801184var 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+ }
11811191
11821192var code = new sb . StringBuilder ( ) ;
11831193code . 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' ) ;
11851195
11861196this . loading = true ;
11871197kernelApi . executePython ( code . toString ( ) , function ( result ) {
@@ -1193,62 +1203,101 @@ define([
11931203// var columnList = data.columns;
11941204var indexList = data . index ;
11951205var 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 } } ) ;
11961209
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' ;
12331221}
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' ;
12371239}
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>' ) ;
12391254} ) ;
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' ) ;
12421258table . 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+
12521301// load info
12531302that . loadInfo ( ) ;
12541303// add to stack
@@ -1257,6 +1306,11 @@ define([
12571306var replacedCode = codeStr . replaceAll ( that . state . tempObj , that . state . returnObj ) ;
12581307that . setPreview ( replacedCode ) ;
12591308}
1309+
1310+ // if scrollPos is saved, go to the position
1311+ if ( scrollPos >= 0 ) {
1312+ $ ( that . wrapSelector ( '.vp-fe-table' ) ) . scrollTop ( scrollPos ) ;
1313+ }
12601314
12611315that . loading = false ;
12621316} ) ;
@@ -1592,7 +1646,7 @@ define([
15921646// more rows
15931647$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE_MORE ) , function ( ) {
15941648that . state . lines += TABLE_LINES ;
1595- that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . SHOW ) ) ;
1649+ that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . SHOW ) , true ) ;
15961650} ) ;
15971651
15981652// click toolbar item