Dynamically cell rendering in ag-grid for polymer 3












0















How should the polymer ag-grid example be changed to render instead of "Change me" button, button with dynamic generated text from data model (Toyota, Ford or Porsche)



In my use case I need to add a hyperlink based on the row data and a tooltip on a row.



ag-grid-polymer-example.js:



import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

import ClickableCellRenderer from './clickable-renderer'

class AgGridPolymerExample extends PolymerElement {
static get template() {
return html`
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-theme-balham.css">

<div style="width: 800px;">
<h1>Simple ag-Grid Polymer 3 Example</h1>
<ag-grid-polymer style="width: 100%; height: 350px;"
class="ag-theme-balham"
rowData="{{rowData}}"
columnDefs="{{columnDefs}}"
components="{{components}}"
on-first-data-rendered="{{firstDataRendered}}"
></ag-grid-polymer>
</div>
`;
}

constructor() {
super();

this.columnDefs = [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"},
{
headerName: "Clickable Component",
field: "make",
cellRendererFramework: 'clickable-renderer'
}
];

this.rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];

this.components = {
clickableCellRenderer: ClickableCellRenderer,
}
}

firstDataRendered(params) {
params.api.sizeColumnsToFit()
}
}

customElements.define('ag-grid-polymer-example', AgGridPolymerExample);


clicable-renderer.js



    import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

export default class ClickableCellRenderer extends PolymerElement {
static get template() {
return html`
<button style="height: 21px" on-click="click">Click Me</button>
`;
}

agInit(params) {
this.params = params;

this.cell = {row: params.value, col: params.colDef.headerName};
}

click() {
console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
}
}

customElements.define('clickable-renderer', ClickableCellRenderer);


index.html



    <!doctype html>
<html lang="en">
<head>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js"></script>

<script type="module" src="ag-grid-polymer-example.js"></script>
</head>
<body>
<ag-grid-polymer-example></ag-grid-polymer-example>
</body>
</html>


I guess, I should somehow write template value form agInit(), where I have data i need in "this.params.data" at some path. (?)










share|improve this question

























  • If I am not wrong, you want to add a button on rows?

    – HakanC
    Nov 24 '18 at 11:58











  • 1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

    – Tihomir
    Nov 24 '18 at 12:01













  • Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

    – Tihomir
    Nov 24 '18 at 12:06











  • I see. I think you will need to change component itself

    – HakanC
    Nov 24 '18 at 12:06











  • I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

    – HakanC
    Nov 24 '18 at 12:11


















0















How should the polymer ag-grid example be changed to render instead of "Change me" button, button with dynamic generated text from data model (Toyota, Ford or Porsche)



In my use case I need to add a hyperlink based on the row data and a tooltip on a row.



ag-grid-polymer-example.js:



import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

import ClickableCellRenderer from './clickable-renderer'

class AgGridPolymerExample extends PolymerElement {
static get template() {
return html`
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-theme-balham.css">

<div style="width: 800px;">
<h1>Simple ag-Grid Polymer 3 Example</h1>
<ag-grid-polymer style="width: 100%; height: 350px;"
class="ag-theme-balham"
rowData="{{rowData}}"
columnDefs="{{columnDefs}}"
components="{{components}}"
on-first-data-rendered="{{firstDataRendered}}"
></ag-grid-polymer>
</div>
`;
}

constructor() {
super();

this.columnDefs = [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"},
{
headerName: "Clickable Component",
field: "make",
cellRendererFramework: 'clickable-renderer'
}
];

this.rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];

this.components = {
clickableCellRenderer: ClickableCellRenderer,
}
}

firstDataRendered(params) {
params.api.sizeColumnsToFit()
}
}

customElements.define('ag-grid-polymer-example', AgGridPolymerExample);


clicable-renderer.js



    import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

export default class ClickableCellRenderer extends PolymerElement {
static get template() {
return html`
<button style="height: 21px" on-click="click">Click Me</button>
`;
}

agInit(params) {
this.params = params;

this.cell = {row: params.value, col: params.colDef.headerName};
}

click() {
console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
}
}

customElements.define('clickable-renderer', ClickableCellRenderer);


index.html



    <!doctype html>
<html lang="en">
<head>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js"></script>

<script type="module" src="ag-grid-polymer-example.js"></script>
</head>
<body>
<ag-grid-polymer-example></ag-grid-polymer-example>
</body>
</html>


I guess, I should somehow write template value form agInit(), where I have data i need in "this.params.data" at some path. (?)










share|improve this question

























  • If I am not wrong, you want to add a button on rows?

    – HakanC
    Nov 24 '18 at 11:58











  • 1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

    – Tihomir
    Nov 24 '18 at 12:01













  • Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

    – Tihomir
    Nov 24 '18 at 12:06











  • I see. I think you will need to change component itself

    – HakanC
    Nov 24 '18 at 12:06











  • I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

    – HakanC
    Nov 24 '18 at 12:11
















0












0








0








How should the polymer ag-grid example be changed to render instead of "Change me" button, button with dynamic generated text from data model (Toyota, Ford or Porsche)



In my use case I need to add a hyperlink based on the row data and a tooltip on a row.



ag-grid-polymer-example.js:



import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

import ClickableCellRenderer from './clickable-renderer'

class AgGridPolymerExample extends PolymerElement {
static get template() {
return html`
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-theme-balham.css">

<div style="width: 800px;">
<h1>Simple ag-Grid Polymer 3 Example</h1>
<ag-grid-polymer style="width: 100%; height: 350px;"
class="ag-theme-balham"
rowData="{{rowData}}"
columnDefs="{{columnDefs}}"
components="{{components}}"
on-first-data-rendered="{{firstDataRendered}}"
></ag-grid-polymer>
</div>
`;
}

constructor() {
super();

this.columnDefs = [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"},
{
headerName: "Clickable Component",
field: "make",
cellRendererFramework: 'clickable-renderer'
}
];

this.rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];

this.components = {
clickableCellRenderer: ClickableCellRenderer,
}
}

firstDataRendered(params) {
params.api.sizeColumnsToFit()
}
}

customElements.define('ag-grid-polymer-example', AgGridPolymerExample);


clicable-renderer.js



    import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

export default class ClickableCellRenderer extends PolymerElement {
static get template() {
return html`
<button style="height: 21px" on-click="click">Click Me</button>
`;
}

agInit(params) {
this.params = params;

this.cell = {row: params.value, col: params.colDef.headerName};
}

click() {
console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
}
}

customElements.define('clickable-renderer', ClickableCellRenderer);


index.html



    <!doctype html>
<html lang="en">
<head>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js"></script>

<script type="module" src="ag-grid-polymer-example.js"></script>
</head>
<body>
<ag-grid-polymer-example></ag-grid-polymer-example>
</body>
</html>


I guess, I should somehow write template value form agInit(), where I have data i need in "this.params.data" at some path. (?)










share|improve this question
















How should the polymer ag-grid example be changed to render instead of "Change me" button, button with dynamic generated text from data model (Toyota, Ford or Porsche)



In my use case I need to add a hyperlink based on the row data and a tooltip on a row.



ag-grid-polymer-example.js:



import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

import ClickableCellRenderer from './clickable-renderer'

class AgGridPolymerExample extends PolymerElement {
static get template() {
return html`
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="../node_modules/ag-grid-community/dist/styles/ag-theme-balham.css">

<div style="width: 800px;">
<h1>Simple ag-Grid Polymer 3 Example</h1>
<ag-grid-polymer style="width: 100%; height: 350px;"
class="ag-theme-balham"
rowData="{{rowData}}"
columnDefs="{{columnDefs}}"
components="{{components}}"
on-first-data-rendered="{{firstDataRendered}}"
></ag-grid-polymer>
</div>
`;
}

constructor() {
super();

this.columnDefs = [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"},
{
headerName: "Clickable Component",
field: "make",
cellRendererFramework: 'clickable-renderer'
}
];

this.rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];

this.components = {
clickableCellRenderer: ClickableCellRenderer,
}
}

firstDataRendered(params) {
params.api.sizeColumnsToFit()
}
}

customElements.define('ag-grid-polymer-example', AgGridPolymerExample);


clicable-renderer.js



    import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

export default class ClickableCellRenderer extends PolymerElement {
static get template() {
return html`
<button style="height: 21px" on-click="click">Click Me</button>
`;
}

agInit(params) {
this.params = params;

this.cell = {row: params.value, col: params.colDef.headerName};
}

click() {
console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
}
}

customElements.define('clickable-renderer', ClickableCellRenderer);


index.html



    <!doctype html>
<html lang="en">
<head>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js"></script>

<script type="module" src="ag-grid-polymer-example.js"></script>
</head>
<body>
<ag-grid-polymer-example></ag-grid-polymer-example>
</body>
</html>


I guess, I should somehow write template value form agInit(), where I have data i need in "this.params.data" at some path. (?)







javascript web-component ag-grid polymer-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 17:27







Tihomir

















asked Nov 23 '18 at 14:05









TihomirTihomir

748




748













  • If I am not wrong, you want to add a button on rows?

    – HakanC
    Nov 24 '18 at 11:58











  • 1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

    – Tihomir
    Nov 24 '18 at 12:01













  • Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

    – Tihomir
    Nov 24 '18 at 12:06











  • I see. I think you will need to change component itself

    – HakanC
    Nov 24 '18 at 12:06











  • I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

    – HakanC
    Nov 24 '18 at 12:11





















  • If I am not wrong, you want to add a button on rows?

    – HakanC
    Nov 24 '18 at 11:58











  • 1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

    – Tihomir
    Nov 24 '18 at 12:01













  • Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

    – Tihomir
    Nov 24 '18 at 12:06











  • I see. I think you will need to change component itself

    – HakanC
    Nov 24 '18 at 12:06











  • I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

    – HakanC
    Nov 24 '18 at 12:11



















If I am not wrong, you want to add a button on rows?

– HakanC
Nov 24 '18 at 11:58





If I am not wrong, you want to add a button on rows?

– HakanC
Nov 24 '18 at 11:58













1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

– Tihomir
Nov 24 '18 at 12:01







1. I want to render an hyperlink that is based on row data. 2. Wold like to add tootip for some rows depending on their data.

– Tihomir
Nov 24 '18 at 12:01















Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

– Tihomir
Nov 24 '18 at 12:06





Let's say, button is replaced with hyperlink and contains maker value from the model (Toyota, Ford,...)

– Tihomir
Nov 24 '18 at 12:06













I see. I think you will need to change component itself

– HakanC
Nov 24 '18 at 12:06





I see. I think you will need to change component itself

– HakanC
Nov 24 '18 at 12:06













I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

– HakanC
Nov 24 '18 at 12:11







I thınk you may add a <a href=[[..]]> while rendering data of rows. (Inside element's repeating rows down. I will check in element. I did't see in the element's own -properties)

– HakanC
Nov 24 '18 at 12:11














1 Answer
1






active

oldest

votes


















1














To stay close to the original example, assume we want to render button title dynamically.
It was required to add public property and asign a value to it in agInit() as shown in the example:



import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'ag-grid-polymer';

export default class ClickableCellRenderer extends PolymerElement {
static get template() {
return html`
<button style="height: 21px" on-click="click">Click [[btnTitle]]</button>
`;
}

static get properties() {
return {
btnTitle: {
type: String,

}
}
}

agInit(params) {
this.cell = {row: params.value, col: params.colDef.headerName};
this.btnTitle = params.data.make;

}

click() {
console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
}
}

customElements.define('clickable-renderer', ClickableCellRenderer);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448163%2fdynamically-cell-rendering-in-ag-grid-for-polymer-3%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To stay close to the original example, assume we want to render button title dynamically.
    It was required to add public property and asign a value to it in agInit() as shown in the example:



    import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
    import 'ag-grid-polymer';

    export default class ClickableCellRenderer extends PolymerElement {
    static get template() {
    return html`
    <button style="height: 21px" on-click="click">Click [[btnTitle]]</button>
    `;
    }

    static get properties() {
    return {
    btnTitle: {
    type: String,

    }
    }
    }

    agInit(params) {
    this.cell = {row: params.value, col: params.colDef.headerName};
    this.btnTitle = params.data.make;

    }

    click() {
    console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
    }
    }

    customElements.define('clickable-renderer', ClickableCellRenderer);





    share|improve this answer




























      1














      To stay close to the original example, assume we want to render button title dynamically.
      It was required to add public property and asign a value to it in agInit() as shown in the example:



      import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
      import 'ag-grid-polymer';

      export default class ClickableCellRenderer extends PolymerElement {
      static get template() {
      return html`
      <button style="height: 21px" on-click="click">Click [[btnTitle]]</button>
      `;
      }

      static get properties() {
      return {
      btnTitle: {
      type: String,

      }
      }
      }

      agInit(params) {
      this.cell = {row: params.value, col: params.colDef.headerName};
      this.btnTitle = params.data.make;

      }

      click() {
      console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
      }
      }

      customElements.define('clickable-renderer', ClickableCellRenderer);





      share|improve this answer


























        1












        1








        1







        To stay close to the original example, assume we want to render button title dynamically.
        It was required to add public property and asign a value to it in agInit() as shown in the example:



        import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
        import 'ag-grid-polymer';

        export default class ClickableCellRenderer extends PolymerElement {
        static get template() {
        return html`
        <button style="height: 21px" on-click="click">Click [[btnTitle]]</button>
        `;
        }

        static get properties() {
        return {
        btnTitle: {
        type: String,

        }
        }
        }

        agInit(params) {
        this.cell = {row: params.value, col: params.colDef.headerName};
        this.btnTitle = params.data.make;

        }

        click() {
        console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
        }
        }

        customElements.define('clickable-renderer', ClickableCellRenderer);





        share|improve this answer













        To stay close to the original example, assume we want to render button title dynamically.
        It was required to add public property and asign a value to it in agInit() as shown in the example:



        import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
        import 'ag-grid-polymer';

        export default class ClickableCellRenderer extends PolymerElement {
        static get template() {
        return html`
        <button style="height: 21px" on-click="click">Click [[btnTitle]]</button>
        `;
        }

        static get properties() {
        return {
        btnTitle: {
        type: String,

        }
        }
        }

        agInit(params) {
        this.cell = {row: params.value, col: params.colDef.headerName};
        this.btnTitle = params.data.make;

        }

        click() {
        console.log("Child Cell Clicked: " + JSON.stringify(this.cell));
        }
        }

        customElements.define('clickable-renderer', ClickableCellRenderer);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 16:38









        TihomirTihomir

        748




        748






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448163%2fdynamically-cell-rendering-in-ag-grid-for-polymer-3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'