Таблица Jquery Bootgrid с атрибутом заголовка удаляет атрибут заголовка после привязки данных

Я пытаюсь создать очень простую таблицу загрузочной сетки jquery с атрибутом заголовка, чтобы заголовок оставался липким при прокрутке.

<table id="grid" class="table table-condensed table-hover table-striped">
    <thead>
        <tr>
            <th caption="ID" data-column-id="id" data-type="numeric"></th>
            <th caption="Sender" data-column-id="sender"></th>
            <th caption="Received" data-column-id="received" data-order="desc"></th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

После привязки данных визуализированная таблица выглядит так, как показано ниже, и привязка данных в порядке.

<table id="grid" class="table table-condensed table-hover table-striped">
        <thead>
            <tr>
                <th data-column-id="id" data-type="numeric"></th>
                <th data-column-id="sender"></th>
                <th data-column-id="received" data-order="desc"></th>
            </tr>
        </thead>
        <tbody>data rows goes here.                  
        </tbody>
    </table>

Любое предложение, как я могу сказать jquery-bootgrid, чтобы остановить удаление атрибута заголовка?

Большое спасибо.


person Muralidharan Deenathayalan    schedule 25.03.2019    source источник


Ответы (1)


Наконец я понял это, и это исправлено.

В файле jquery.bootgrid.js найдите метод loadColumns и включите атрибут заголовка, как указано ниже.

Шаг 1. Изменение метода loadColumns()

function loadColumns()
    {
        var that = this,
            firstHeadRow = this.element.find("thead > tr").first(),
            sorted = false;

        /*jshint -W018*/
        firstHeadRow.children().each(function ()
        {
            var $this = $(this),
                data = $this.data(),
                column = {
                    caption: $this[0].attributes.caption.value,//Find better way
                    id: data.columnId,
....
...
}

Шаг 2. Изменения в методе renderTableHeader()

function renderTableHeader()
{ ....
  ....

$.each(this.columns, function (index, column)
    {
        if (column.visible)
        {

            //console.log(column.caption);
            var sortOrder = that.sortDictionary[column.id],
                iconCss = ((sorting && sortOrder && sortOrder === "asc") ? css.iconUp :
                    (sorting && sortOrder && sortOrder === "desc") ? css.iconDown : ""),
                icon = tpl.icon.resolve(getParams.call(that, { iconCss: iconCss })),
                align = column.headerAlign,
                cssClass = (column.headerCssClass.length > 0) ? " " + column.headerCssClass : "",
                caption = column.caption; //caption passed to template 
 ....
 ....   }

Шаг 3. Изменения в шаблоне ячейки заголовка.

Найдите эту переменную headercell и добавьте атрибут заголовка в шаблон.

headerCell: "<th data-column-id=\"{{ctx.column.id}}\" caption=\"{{ctx.column.caption}}\"  class=\"{{ctx.css}}\" style=\"{{ctx.style}}\"><a href=\"javascript:void(0);\" class=\"{{css.columnHeaderAnchor}} {{ctx.sortable}}\"><span class=\"{{css.columnHeaderText}}\">{{ctx.column.text}}</span>{{ctx.icon}}</a></th>",

Надеюсь, это поможет кому-то.

person Muralidharan Deenathayalan    schedule 30.03.2019