Instantsearch.js: TransformData on Header Footer

Created on 3 Nov 2016  路  5Comments  路  Source: algolia/instantsearch.js

Why can't I use TransformData on the header or footer?
Like this:

search.addWidget(
            instantsearch.widgets.refinementList({
                container: '#container',
                attributeName: 'Attribute',
                sortBy: ['name:asc'],
                limit: 10,
                operator: 'and',
                transformData: function(data){
                    data.myValue = "some new value";
                },
                templates: {
                    header: "{{myValue}}"
                }
            })
        );
Question

All 5 comments

@Giovanni-Mattucci I think you need to use:

transformData: {
  header: function() {

  }
}

Let me know how it goes

I tried that and it didn't seem to work.

search.addWidget(
            instantsearch.widgets.refinementList({
                ...
               transformData: {
                   header: function(data) {
                        /*never actually runs?*/
                        return data.myValue = "some new value";
                        console.log('I am never reached'); //never gets run
                   }
               }
                templates: {
                    header: "{{myValue}}"
                }
            })
        );

Ok so then no that's not feasible, what you can do is pass a function to the header template instead of a string, then return a string of text (not a mustache template).

Would that be ok for you?

@vvo yes what you suggested is the way to go.

search.addWidget(
            instantsearch.widgets.refinementList({
                ...
                templates: {
                    header: function(){
                        var myValue = someOtherData;
                        return "some new value" + myValue
                    }
                }
            })
        );

Being able to TransformData Header and Footer templates would be useful in this case, as only item is supported: https://community.algolia.com/instantsearch.js/v2/widgets/refinementList.html#struct-RefinementListTransforms

Thanks for closing this old issue @Giovanni-Mattucci 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zackify picture zackify  路  4Comments

timkelty picture timkelty  路  3Comments

bobylito picture bobylito  路  3Comments

egyprotech picture egyprotech  路  3Comments

anthonyBertrant picture anthonyBertrant  路  3Comments