Подтвердить что ты не робот

JQuery dataTables - значок выравнивания по левому краю

поскольку вы можете видеть, что значки сортировки на моем Datatable находятся в правом углу столбца:

enter image description here

Можно ли выровнять их слева, чтобы они отображались сразу после текста?

т.

# ^            Technician ^              Completed Date ^

Спасибо

Код в соответствии с запросом:

    <div class="dataTable_wrapper">
        <table class="table table-striped table-hover" id="table-d">
            <thead>
            <tr>
                <th>{% trans %} id {% endtrans %}</th>
                <th>{% trans %} technician {% endtrans %}</th>
                <th>{% trans %} date {% endtrans %}</th>
                <th>{% trans %} summary {% endtrans %}</th>
            </tr>
            </thead>
        </table>
    </div>

и

$('#table-d').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "{{ path('table_data') }}",
    "pageLength": 10
})'
4b9b3361

Ответ 1

Нет, это невозможно сразу после текста, так как стрелки на самом деле являются фоновыми изображениями в CSS-классах, динамически подключаемых к <th>. Но вы можете изменить положение справа налево:

table.dataTable thead .sorting_asc {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_asc.png") no-repeat center left;
}
table.dataTable thead .sorting_desc {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_desc.png") no-repeat center left;
}
table.dataTable thead .sorting {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_both.png") no-repeat center left;
}

enter image description here

demo → http://jsfiddle.net/ttcz5odt/


Обновление - как разместить значки стрелок непосредственно после текста.

Сделал несколько дополнительных мыслей - с небольшим "взломом" это действительно возможно. Трюк состоит в том, чтобы отключить фон <th> и непрерывно вводить/удалять <span> с исходными фоновую таблицу данных.

CSS (кроме отключения оригинала):

span.arrow-hack {
  margin-left: 5px;
}
span.asc {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_asc.png") no-repeat center right;
}
span.desc {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_desc.png") no-repeat center right;
}
span.sort {
  background: url("http://cdn.datatables.net/1.10.0/images/sort_both.png") no-repeat center right;
}

script:

var spanSorting = '<span class="arrow-hack sort">&nbsp;&nbsp;&nbsp;</span>',
    spanAsc = '<span class="arrow-hack asc">&nbsp;&nbsp;&nbsp;</span>',
    spanDesc = '<span class="arrow-hack desc">&nbsp;&nbsp;&nbsp;</span>';

$("#example").on('click', 'th', function() {
    $("#example thead th").each(function(i, th) {
        $(th).find('.arrow-hack').remove();
        var html = $(th).html(),
            cls = $(th).attr('class');
        switch (cls) {
            case 'sorting_asc' : 
                $(th).html(html+spanAsc); break;
            case 'sorting_desc' : 
                $(th).html(html+spanDesc); break;
            default : 
                $(th).html(html+spanSorting); break;
        }
    });     
});    

обновить значки стрелок:

$("#example th").first().click().click();

Теперь это похоже на то, что мы хотели!: enter image description here

demo → http://jsfiddle.net/dmn4q141/

Ответ 2

Мне удалось сделать это, применив следующие стили (лучше, если применить в качестве последнего определения файла css include)

/**
 * Datatables Sorting icons on left
 */

table.dataTable thead > tr > th {
    padding-left: 30px !important;
    padding-right: initial !important;
}

table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:after {
    left: 8px !important;
    right: auto !important;
}

Ответ 3

Вы можете изменить css как:

table.dataTable thead .sorting, table.dataTable thead .sorting_asc, table.dataTable thead .sorting_desc, table.dataTable thead .sorting_asc_disabled, table.dataTable thead .sorting_desc_disabled{
    background-position: left center;
}

следующее: css, чтобы стрелка стрелки и заголовок были более привлекательными. (не требуется)

table.dataTable thead .sorting, table.dataTable thead .sorting_asc, table.dataTable thead .sorting_desc, table.dataTable thead .sorting_asc_disabled, table.dataTable thead .sorting_desc_disabled{
    background-position: 5px center;
}
table.dataTable thead th, table.dataTable thead td {
    padding: 10px 18px 10px 28px;           
}

Ответ 5

Вот простой и простой ответ.

для моего экрана достаточно 160 пикселей.

Отрегулируйте его в соответствии с вашими потребностями.

 #table-d thead .sorting::after, table.dataTable thead .sorting_asc::after, table.dataTable thead .sorting_desc::after 
 {
        left: 160px;
        right: 0;
  }