@@ -1527,6 +1527,60 @@ function _Report_Extensions_ContextMenu() {
1527
1527
Log . logText ( "Open visual context menu by right click on data points and click on added items to see events in Log window." ) ;
1528
1528
}
1529
1529
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
+
1530
1584
// ---- Page Operations ----------------------------------------------------
1531
1585
1532
1586
function _Page_SetActive ( ) {
@@ -2191,7 +2245,7 @@ function _Visual_GetSlicer() {
2191
2245
2192
2246
activePage . getVisuals ( )
2193
2247
. then ( function ( visuals ) {
2194
- // Retrieve the wanted visual.
2248
+ // Retrieve the target visual.
2195
2249
var slicer = visuals . filter ( function ( visual ) {
2196
2250
return visual . type == "slicer" && visual . name == "4d55baaa5eddde4cdf90" ;
2197
2251
} ) [ 0 ] ;
@@ -2253,7 +2307,7 @@ function _Visual_SetSlicer() {
2253
2307
2254
2308
activePage . getVisuals ( )
2255
2309
. then ( function ( visuals ) {
2256
- // Retrieve the wanted visual.
2310
+ // Retrieve the target visual.
2257
2311
var slicer = visuals . filter ( function ( visual ) {
2258
2312
return visual . type == "slicer" && visual . name == "4d55baaa5eddde4cdf90" ;
2259
2313
} ) [ 0 ] ;
@@ -2313,7 +2367,7 @@ function _Visual_SetFilters() {
2313
2367
activePage . getVisuals ( )
2314
2368
. then ( function ( visuals ) {
2315
2369
2316
- // Retrieve the wanted visual.
2370
+ // Retrieve the target visual.
2317
2371
var visual = visuals . filter ( function ( visual ) {
2318
2372
return visual . name == "VisualContainer4" ;
2319
2373
} ) [ 0 ] ;
@@ -2356,7 +2410,7 @@ function _Visual_GetFilters() {
2356
2410
activePage . getVisuals ( )
2357
2411
. then ( function ( visuals ) {
2358
2412
2359
- // Retrieve the wanted visual.
2413
+ // Retrieve the target visual.
2360
2414
var visual = visuals . filter ( function ( visual ) {
2361
2415
return visual . name == "VisualContainer4" ;
2362
2416
} ) [ 0 ] ;
@@ -2397,7 +2451,7 @@ function _Visual_RemoveFilters() {
2397
2451
activePage . getVisuals ( )
2398
2452
. then ( function ( visuals ) {
2399
2453
2400
- // Retrieve the wanted visual.
2454
+ // Retrieve the target visual.
2401
2455
var visual = visuals . filter ( function ( visual ) {
2402
2456
return visual . name == "VisualContainer4" ;
2403
2457
} ) [ 0 ] ;
@@ -2441,7 +2495,7 @@ function _Visual_ExportData_Summarized() {
2441
2495
activePage . getVisuals ( )
2442
2496
. then ( function ( visuals ) {
2443
2497
2444
- // Retrieve the wanted visual.
2498
+ // Retrieve the target visual.
2445
2499
var visual = visuals . filter ( function ( visual ) {
2446
2500
return visual . name == "VisualContainer4" ;
2447
2501
} ) [ 0 ] ;
@@ -2486,7 +2540,7 @@ function _Visual_ExportData_Underlying() {
2486
2540
activePage . getVisuals ( )
2487
2541
. then ( function ( visuals ) {
2488
2542
2489
- // Retrieve the wanted visual.
2543
+ // Retrieve the target visual.
2490
2544
var visual = visuals . filter ( function ( visual ) {
2491
2545
return visual . name == "VisualContainer4" ;
2492
2546
} ) [ 0 ] ;
@@ -2968,4 +3022,3 @@ function _Report_Authoring_ResetProperty() {
2968
3022
Log . log ( errors ) ;
2969
3023
} ) ;
2970
3024
}
2971
-
0 commit comments