@@ -266,6 +266,75 @@ PivotView.prototype.removeMessage = function () {
266
266
267
267
} ;
268
268
269
+ /**
270
+ * @param {* } value1
271
+ * @param {string } operator
272
+ * @param {* } value2 - fixed value
273
+ * @private
274
+ * @return {boolean }
275
+ */
276
+ PivotView . prototype . _matchCondition = function ( value1 , operator , value2 ) {
277
+
278
+ switch ( operator ) {
279
+ case "=" : return value1 == value2 ;
280
+ case "<>" : return value1 != value2 ;
281
+ case ">" : return value1 > value2 ;
282
+ case ">=" : return value1 >= value2 ;
283
+ case "<" : return value1 < value2 ;
284
+ case "<=" : return value1 <= value2 ;
285
+ case "IN" : return value2 . toString ( ) . indexOf ( value1 ) !== - 1 ; // how does it normally work?
286
+ case "BETWEEN" : return value1 >= value2 . split ( "," ) [ 0 ] && value1 <= value2 . split ( "," ) [ 1 ] ;
287
+ case "IS NULL" : return ! value1 ;
288
+ default : {
289
+ console . error ( "Formatting error: unknown format operator \"" + operator + "\"" ) ;
290
+ return false ;
291
+ }
292
+ }
293
+
294
+ } ;
295
+
296
+ /**
297
+ * Applies conditional formatting for element.
298
+ *
299
+ * @param {object } rules - Special object that contain formatting rules.
300
+ * @param {string } key - Position y,x separated by comma or empty string for global.
301
+ * @param {* } value - Original value to format (comparator).
302
+ * @param {HTMLElement } element - element to format.
303
+ */
304
+ PivotView . prototype . applyConditionalFormatting = function ( rules , key , value , element ) {
305
+
306
+ var actualRules = rules [ "" ] || [ ] ,
307
+ p , i , rule , html , xs , num ;
308
+ actualRules = actualRules . concat ( rules [ key ] || [ ] ) ;
309
+ if ( ( xs = key . split ( "," ) ) . length === 2 ) {
310
+ actualRules = actualRules . concat ( rules [ xs [ 0 ] + "," ] || [ ] , rules [ "," + xs [ 1 ] ] || [ ] ) ;
311
+ }
312
+
313
+ for ( p in actualRules ) {
314
+
315
+ rule = actualRules [ p ] ;
316
+ if ( ! this . _matchCondition ( value , rule [ "operator" ] , rule [ "value" ] ) ) continue ;
317
+
318
+ // apply formatting
319
+ if ( rule [ "style" ] )
320
+ element . setAttribute ( "style" , ( element . getAttribute ( "style" ) || "" ) + rule [ "style" ] ) ;
321
+ if ( rule [ "icon" ] ) {
322
+ element . textContent = "" ; html = "<div style=\"overflow: hidden; height: 16px;\">" ;
323
+ num = parseInt ( rule [ "iconCount" ] ) || 1 ;
324
+ for ( i = 0 ; i < num ; i ++ ) {
325
+ html += "<img alt=\"*\" style=\"padding-right:2px; height: 100%;\" " +
326
+ "src=\"" + rule [ "icon" ] + "\"/>" ;
327
+ }
328
+ // LPT won't change default format (f.e. text-align) for content.
329
+ // element.className = (element.className || "") + " formatLeft";
330
+ element . innerHTML = html + "</div>" ;
331
+ }
332
+ if ( rule [ "text" ] ) element . textContent = rule [ "text" ] ;
333
+
334
+ }
335
+
336
+ } ;
337
+
269
338
/**
270
339
* @param container
271
340
*/
@@ -534,6 +603,17 @@ PivotView.prototype.renderRawData = function (data) {
534
603
}
535
604
}
536
605
if ( rawData [ y ] [ x ] . style ) td . setAttribute ( "style" , rawData [ y ] [ x ] . style ) ;
606
+ if (
607
+ this . controller . CONFIG . conditionalFormattingOn // totals formatting present
608
+ && ! ( info . SUMMARY_SHOWN && rawData . length - 1 === y ) // exclude totals formatting
609
+ ) {
610
+ this . applyConditionalFormatting (
611
+ data [ "conditionalFormatting" ] ,
612
+ ( y - info . topHeaderRowsNumber + 1 ) + "," + ( x - info . leftHeaderColumnsNumber + 1 ) ,
613
+ rawData [ y ] [ x ] . value ,
614
+ td
615
+ ) ;
616
+ }
537
617
538
618
// add handlers
539
619
td . addEventListener ( CLICK_EVENT , ( function ( x , y , cell ) {
0 commit comments