Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       CreateAgGridDataSource: () ->
  2.         return (
  3.           getRows: (params) =>
  4.             rowsThisPage = []
  5.             startRow = params.request.startRow
  6.             endRow = params.request.endRow
  7.  
  8.             # if we are sorting and/or filtering...
  9.             if @gridSortChanged or @gridFilterChanged  
  10.               if @gridOptions.api.getSortModel()? and @gridOptions.api.getSortModel()[0]?
  11.                 @gridSortColumn = @gridOptions.api.getSortModel()[0].colId
  12.  
  13.                 #if ascending sort
  14.                 if @gridOptions.api.getSortModel()[0].sort == 'asc'
  15.                   @gridSortType = @gridSortColumn + "-ascending"
  16.                 #if descending sort
  17.                 else if @gridOptions.api.getSortModel()[0].sort == 'desc'
  18.                   @gridSortType = @gridSortColumn + "-descending"
  19.  
  20.               @gridSortBy(@gridSortColumn, @gridSortType, @advanceFilters).then(() =>
  21.                 rowsThisPage = @works.slice(startRow, endRow)
  22.  
  23.                 finalRow = -1
  24.                 if endRow >= @works.length
  25.                   finalRow = @works.length
  26.            
  27.                 @gridSortChanged = false
  28.                 @gridFilterChanged = false
  29.                 @gridSortColumn = ''
  30.                 @gridSortType = ''
  31.  
  32.                 setTimeout(()=>                
  33.                   params.successCallback(rowsThisPage, finalRow)
  34.                 , 0)
  35.               )            
  36.             else
  37.  
  38.               # find out if the user clicked a group to expand
  39.               groupKeys = params.request.groupKeys
  40.              
  41.               # if the user did not expand a group...
  42.               if groupKeys.length == 0
  43.                 rowsThisPage = @works.slice(startRow, endRow)
  44.                 @gridLoadMore(@advanceFilters).then(() =>
  45.                   finalRow = -1
  46.                   if endRow >= @works.length
  47.                     finalRow = @works.length
  48.  
  49.                   setTimeout(()=>        
  50.                     params.successCallback(rowsThisPage, finalRow)
  51.                   , 0)    
  52.                 )
  53.               # the user has expanded a group, so check that we have parent node data...
  54.               else if params.parentNode? and params.parentNode.data?
  55.                 parentId = params.parentNode.data.id
  56.  
  57.                 # populate child list in parent node's row group
  58.                 @gridLoadChildren(parentId).then((res) =>
  59.                   setTimeout(()=>
  60.                     params.successCallback(@childWorks, @childWorks.length)
  61.                   ,0)
  62.                 )
  63.         )
  64.        
  65.       onGridReady: (event) ->
  66.         initialRowRenderLimit = Math.floor(@viewportHeight / @gridRowRenderDivisor)
  67.  
  68.         @gridFetchInventory(initialRowRenderLimit).then(() =>
  69.           @gridDatasource = @CreateAgGridDataSource()
  70.           @gridOptions.api.setServerSideDatasource(@gridDatasource)
  71.           @gridLoadMore().then()
  72.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement