使用 jqgrid 按日期搜索

Search by date with jqgrid

我在 C# 上使用 Jqgrid,尝试时遇到问题 按日期搜索,因为 colModel 中的字段 'fecha' 是实体上的日期时间 因此,网格从 json 获得的值如下所示:/Date(1514869200000)/ 但是 "formatter: 'date'" 的值看起来像:02/01/2018.

当我尝试搜索时,字段按原始值搜索 (/Date(1514869200000)) 没有我想要的日期

抱歉我的英语不好,希望有人能理解我。

这是我的 .js

$(function () {
$('#grid').jqGrid({
    url: "/Empleados/BuscarEmpleados",
    datatype: 'json',
    mtype: 'Get',
    colNames: ['ID', 'Nombre', 'Cargo', 'Móvil', 'Fecha Inicio', 'Estado', 'Opciones'],
    colModel: [
        { label: "ID", key: true, name: 'id', index: 'id', width: '100px' },
        { label: 'Nombre', name: 'nombre', index: 'nombre', width: '280px', searchoptions: { sopt: ['cn', 'eq'] } },
        { label: 'Cargo', name: 'cargo', index: 'cargo', width: '160px', searchoptions: { sopt: ['cn', 'eq'] } },
        { label: 'Movil', name: 'movil', index: 'movil', width: '140px', searchoptions: { sopt: ['cn', 'eq'] } },
        { label: 'Fecha Inicio', name: 'fecha', index: 'fecha', formatter: 'date',
            formatoptions: { newformat: 'd/m/Y', srcformat: 'd/m/Y' }, searchoptions: { sopt: ['cn', 'eq', 'gt'] }, width: '150px' },
        { name: 'estado', index: 'estado', width: '155px', search: false },
        { name: 'Opciones', index: 'Opciones', formatter: OpcionesEmpleado, search: false, width: '300px' }
    ],
    pager: jQuery('#pager'),
    rowNum: 10,
    rowList: [10, 20, 30, 40],
    height: "100%",
    viewRecords: true,
    loadonce: true,
    caption: "Empleados",
    emptyRecords: "No se han encontrado coincidencias",
    jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false
    },
    autowidth: true,
    multiselect: false,
}).navGrid('#pager', {
    edit: false,
    add: false,
    del: false,
    search: true,
    refresh: true
});

您需要添加

sorttype: "date"

属性 到列的定义 fecha (带有日期的列)。