@@ -1527,6 +1527,60 @@ function _Report_Extensions_ContextMenu() {
15271527 Log . logText ( "Open visual context menu by right click on data points and click on added items to see events in Log window." ) ;
15281528}
15291529
1530+ function _Visual_Operations_SortVisualBy ( ) {
1531+ // Get models. models contains enums that can be used.
1532+ var models = window [ 'powerbi-client' ] . models ;
1533+
1534+ // Build the sort request.
1535+ // For more information, See https://github.com/Microsoft/PowerBI-JavaScript/wiki/Sort-Visual-By
1536+ const sortByRequest = {
1537+ orderBy : {
1538+ table : "SalesFact" ,
1539+ measure : "Total Category Volume"
1540+ } ,
1541+ direction : models . SortDirection . Descending
1542+ } ;
1543+
1544+ // Get a reference to the embedded report HTML element
1545+ var embedContainer = $ ( '#embedContainer' ) [ 0 ] ;
1546+
1547+ // Get a reference to the embedded report.
1548+ report = powerbi . get ( embedContainer ) ;
1549+
1550+ // Retrieve the page collection and get the visuals for the first page.
1551+ report . getPages ( )
1552+ . then ( function ( pages ) {
1553+
1554+ // Retrieve active page.
1555+ var activePage = pages . filter ( function ( page ) {
1556+ return page . isActive
1557+ } ) [ 0 ] ;
1558+
1559+ activePage . getVisuals ( )
1560+ . then ( function ( visuals ) {
1561+ // Retrieve the target visual.
1562+ var visual = visuals . filter ( function ( visual ) {
1563+ return visual . name === "VisualContainer6" ;
1564+ } ) [ 0 ] ;
1565+
1566+ // Sort the visual's data by direction and data field.
1567+ visual . sortBy ( sortByRequest )
1568+ . then ( function ( ) {
1569+ Log . logText ( "\"Total Category Volume Over Time by Region\" visual was sorted according to the request." )
1570+ } )
1571+ . catch ( function ( errors ) {
1572+ Log . log ( errors ) ;
1573+ } ) ;
1574+ } )
1575+ . catch ( function ( errors ) {
1576+ Log . log ( errors ) ;
1577+ } ) ;
1578+ } )
1579+ . catch ( function ( errors ) {
1580+ Log . log ( errors ) ;
1581+ } ) ;
1582+ }
1583+
15301584// ---- Page Operations ----------------------------------------------------
15311585
15321586function _Page_SetActive ( ) {
@@ -2191,7 +2245,7 @@ function _Visual_GetSlicer() {
21912245
21922246 activePage . getVisuals ( )
21932247 . then ( function ( visuals ) {
2194- // Retrieve the wanted visual.
2248+ // Retrieve the target visual.
21952249 var slicer = visuals . filter ( function ( visual ) {
21962250 return visual . type == "slicer" && visual . name == "4d55baaa5eddde4cdf90" ;
21972251 } ) [ 0 ] ;
@@ -2253,7 +2307,7 @@ function _Visual_SetSlicer() {
22532307
22542308 activePage . getVisuals ( )
22552309 . then ( function ( visuals ) {
2256- // Retrieve the wanted visual.
2310+ // Retrieve the target visual.
22572311 var slicer = visuals . filter ( function ( visual ) {
22582312 return visual . type == "slicer" && visual . name == "4d55baaa5eddde4cdf90" ;
22592313 } ) [ 0 ] ;
@@ -2313,7 +2367,7 @@ function _Visual_SetFilters() {
23132367 activePage . getVisuals ( )
23142368 . then ( function ( visuals ) {
23152369
2316- // Retrieve the wanted visual.
2370+ // Retrieve the target visual.
23172371 var visual = visuals . filter ( function ( visual ) {
23182372 return visual . name == "VisualContainer4" ;
23192373 } ) [ 0 ] ;
@@ -2356,7 +2410,7 @@ function _Visual_GetFilters() {
23562410 activePage . getVisuals ( )
23572411 . then ( function ( visuals ) {
23582412
2359- // Retrieve the wanted visual.
2413+ // Retrieve the target visual.
23602414 var visual = visuals . filter ( function ( visual ) {
23612415 return visual . name == "VisualContainer4" ;
23622416 } ) [ 0 ] ;
@@ -2397,7 +2451,7 @@ function _Visual_RemoveFilters() {
23972451 activePage . getVisuals ( )
23982452 . then ( function ( visuals ) {
23992453
2400- // Retrieve the wanted visual.
2454+ // Retrieve the target visual.
24012455 var visual = visuals . filter ( function ( visual ) {
24022456 return visual . name == "VisualContainer4" ;
24032457 } ) [ 0 ] ;
@@ -2441,7 +2495,7 @@ function _Visual_ExportData_Summarized() {
24412495 activePage . getVisuals ( )
24422496 . then ( function ( visuals ) {
24432497
2444- // Retrieve the wanted visual.
2498+ // Retrieve the target visual.
24452499 var visual = visuals . filter ( function ( visual ) {
24462500 return visual . name == "VisualContainer4" ;
24472501 } ) [ 0 ] ;
@@ -2486,7 +2540,7 @@ function _Visual_ExportData_Underlying() {
24862540 activePage . getVisuals ( )
24872541 . then ( function ( visuals ) {
24882542
2489- // Retrieve the wanted visual.
2543+ // Retrieve the target visual.
24902544 var visual = visuals . filter ( function ( visual ) {
24912545 return visual . name == "VisualContainer4" ;
24922546 } ) [ 0 ] ;
@@ -2968,4 +3022,3 @@ function _Report_Authoring_ResetProperty() {
29683022 Log . log ( errors ) ;
29693023 } ) ;
29703024}
2971-
0 commit comments