Setting data attribute on each row of a jqgrid table

后端 未结 2 435
别那么骄傲
别那么骄傲 2020-12-03 15:30

I am using jqGrid and I\'m trying to add a data- attribute to each tr. I\'m firing the loadComplete event, but I\'m unsure of how to modify each row. Any code samples?

2条回答
  •  旧时难觅i
    2020-12-03 15:57

    In my cases, I set the first column of grid by an identity. And in all my cases, id of each data row of my grids is the value of that identity column.

    jqGrid column:

    colModel: [
    {
    name:'ID',
    label:'...',
    width:1,
    index:'ID'
    ...
    

    Rendered :

     // in retrieved data: ID = 10777
    

    So, if you have similar declarations like me, this could be a useful selector for you and you can simply add your data- attrib to these rows like this:

    $('#trId').prop('data-whatever', 'value');
    

    And if you want the above line to be performed automatically to all rows, you should change it slightly and put it into the gridComplete event of your grid:

    gridComplete: function() { $("tr[role='row']").prop('data-whatever', 'value'); }
    

提交回复
热议问题