|
367 | 367 | }
|
368 | 368 | }
|
369 | 369 | }
|
370 |
| - |
371 | 370 | if (startIndex != null && maxIndex != null) {
|
372 |
| - var delta; |
373 |
| - if (startIndex <= topIndex && maxIndex <= botIndex) { |
374 |
| - // Top range missing - show in the middle of the top and max |
375 |
| - delta = (topIndex + maxIndex) / 2; |
376 |
| - } else if (startIndex > topIndex && maxIndex < botIndex) { |
377 |
| - // Mid range missing - show in the middle of the start and max |
378 |
| - delta = (startIndex + maxIndex) / 2; |
379 |
| - } else if (startIndex > topIndex && maxIndex >= botIndex) { |
380 |
| - // Bottom range missing - show in the middle of the start and bot |
381 |
| - delta = (startIndex + botIndex) / 2; |
382 |
| - } else { |
383 |
| - // Full range missing - show in the middle of the top and bot |
384 |
| - delta = (topIndex + botIndex) / 2; |
385 |
| - } |
386 |
| - delta = delta - topIndex; |
387 |
| - spinnerOffset = $tbody.closest('.mCustomScrollBox').position().top + 3 + (this.getRowHeight($tbody) * delta); |
388 |
| - BLCAdmin.listGrid.showLoadingSpinner($tbody, spinnerOffset); |
389 |
| - |
390 |
| - var params = BLCAdmin.history.getUrlParameters(); |
391 |
| - for (var param in params) { |
392 |
| - baseUrl = BLCAdmin.history.getUrlWithParameter(param, params[param], null, baseUrl); |
393 |
| - } |
394 |
| - |
395 |
| - var url = BLCAdmin.history.getUrlWithParameter('startIndex', startIndex, null, baseUrl); |
396 |
| - url = BLCAdmin.history.getUrlWithParameter('maxIndex', maxIndex, null, url); |
397 |
| - |
398 |
| - //console.log('Loading more records -- ' + url); |
399 |
| - |
400 |
| - BLC.ajax({ url: url, type: 'GET' }, function(data) { |
401 |
| - var $newTbody = data.find('tbody'); |
402 |
| - BLCAdmin.listGrid.paginate.injectRecords($tbody, $newTbody); |
403 |
| - BLCAdmin.listGrid.paginate.releaseLock(); |
404 |
| - |
405 |
| - // now that I've loaded records, see if I need to do it again |
406 |
| - var topIndex = BLCAdmin.listGrid.paginate.getTopVisibleIndex($tbody); |
407 |
| - var topIndexLoaded = BLCAdmin.listGrid.paginate.isIndexLoaded($tbody, topIndex); |
408 |
| - var botIndex = BLCAdmin.listGrid.paginate.getBottomVisibleIndex($tbody); |
409 |
| - var botIndexLoaded = BLCAdmin.listGrid.paginate.isIndexLoaded($tbody, botIndex); |
410 |
| - if (!botIndexLoaded || !topIndexLoaded) { |
411 |
| - BLCAdmin.listGrid.paginate.loadRecords($tbody, baseUrl); |
| 371 | + // If we find that the start index is greater than the max index, we do not |
| 372 | + // need to gather any further records, so don't make an ajax call. We also do not |
| 373 | + // want to show the spinner as nothing needs to be done in the first place. |
| 374 | + if (startIndex <= maxIndex) { |
| 375 | + var delta; |
| 376 | + if (startIndex <= topIndex && maxIndex <= botIndex) { |
| 377 | + // Top range missing - show in the middle of the top and max |
| 378 | + delta = (topIndex + maxIndex) / 2; |
| 379 | + } else if (startIndex > topIndex && maxIndex < botIndex) { |
| 380 | + // Mid range missing - show in the middle of the start and max |
| 381 | + delta = (startIndex + maxIndex) / 2; |
| 382 | + } else if (startIndex > topIndex && maxIndex >= botIndex) { |
| 383 | + // Bottom range missing - show in the middle of the start and bot |
| 384 | + delta = (startIndex + botIndex) / 2; |
412 | 385 | } else {
|
413 |
| - BLCAdmin.listGrid.hideLoadingSpinner($tbody); |
| 386 | + // Full range missing - show in the middle of the top and bot |
| 387 | + delta = (topIndex + botIndex) / 2; |
414 | 388 | }
|
415 |
| - }); |
| 389 | + delta = delta - topIndex; |
| 390 | + spinnerOffset = $tbody.closest('.mCustomScrollBox').position().top + 3 + (this.getRowHeight($tbody) * delta); |
| 391 | + |
| 392 | + |
| 393 | + BLCAdmin.listGrid.showLoadingSpinner($tbody, spinnerOffset); |
| 394 | + |
| 395 | + var params = BLCAdmin.history.getUrlParameters(); |
| 396 | + for (var param in params) { |
| 397 | + baseUrl = BLCAdmin.history.getUrlWithParameter(param, params[param], null, baseUrl); |
| 398 | + } |
| 399 | + |
| 400 | + var url = BLCAdmin.history.getUrlWithParameter('startIndex', startIndex, null, baseUrl); |
| 401 | + url = BLCAdmin.history.getUrlWithParameter('maxIndex', maxIndex, null, url); |
| 402 | + |
| 403 | + //console.log('Loading more records -- ' + url); |
| 404 | + BLC.ajax({ url: url, type: 'GET' }, function(data) { |
| 405 | + var $newTbody = data.find('tbody'); |
| 406 | + BLCAdmin.listGrid.paginate.injectRecords($tbody, $newTbody); |
| 407 | + BLCAdmin.listGrid.paginate.releaseLock(); |
| 408 | + |
| 409 | + // now that I've loaded records, see if I need to do it again |
| 410 | + var topIndex = BLCAdmin.listGrid.paginate.getTopVisibleIndex($tbody); |
| 411 | + var topIndexLoaded = BLCAdmin.listGrid.paginate.isIndexLoaded($tbody, topIndex); |
| 412 | + var botIndex = BLCAdmin.listGrid.paginate.getBottomVisibleIndex($tbody); |
| 413 | + var botIndexLoaded = BLCAdmin.listGrid.paginate.isIndexLoaded($tbody, botIndex); |
| 414 | + if (!botIndexLoaded || !topIndexLoaded) { |
| 415 | + BLCAdmin.listGrid.paginate.loadRecords($tbody, baseUrl); |
| 416 | + } else { |
| 417 | + BLCAdmin.listGrid.hideLoadingSpinner($tbody); |
| 418 | + } |
| 419 | + }); |
| 420 | + } |
416 | 421 | } else {
|
417 | 422 | BLCAdmin.listGrid.paginate.releaseLock();
|
418 | 423 | }
|
|
423 | 428 | // ************************* *
|
424 | 429 |
|
425 | 430 | getRowHeight : function($tbody) {
|
426 |
| - return $tbody.find('tr:not(.blank-padding):first').height(); |
| 431 | + // Updated the code here to return the exact value (possibly float values) of |
| 432 | + // the height of the row. Previously it would round this value which led to |
| 433 | + // inaccurate math. |
| 434 | + return $tbody.find('tr:not(.blank-padding):first')[0].getBoundingClientRect().height; |
427 | 435 | },
|
428 | 436 |
|
429 | 437 | getTopVisibleIndex : function($tbody) {
|
|
440 | 448 | getBottomVisibleIndex : function($tbody) {
|
441 | 449 | var scrollOffset = $tbody.closest('.mCSB_container').position().top;
|
442 | 450 | var trHeight = this.getRowHeight($tbody);
|
443 |
| - var bottomVisibleIndex = Math.floor((scrollOffset * -1 + $tbody.closest('.listgrid-body-wrapper').height() - 4) / trHeight); |
| 451 | + // Updated the code here to use the exact value (possibly float value) of |
| 452 | + // the listgrid body wrapper. Previously it would round this value which |
| 453 | + // led to inaccurate math. |
| 454 | + var bottomVisibleIndex = Math.floor((scrollOffset * -1 + $tbody.closest('.listgrid-body-wrapper')[0].getBoundingClientRect().height - trHeight) / trHeight); |
444 | 455 | return bottomVisibleIndex;
|
445 | 456 | },
|
446 | 457 |
|
|
0 commit comments