Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
sort grid by date
posted

Hi Guy, 

I need to order the grid by date, I pass my code, the column is F

'use strict';
app.factory('informeRentabilidadReportService', ['$injector', '$filter', function ($injector, $filter) {

/*DEPENDENCIAS*/
var resourceService = $injector.get("resourceService");
var str = resourceService.Strings;

var Enum = $injector.get("Enum");
var formatterService = $injector.get("formatterServiceVF");
//var responsiveService = $injector.get("responsiveService");
var templateService = $injector.get("templateVFService");
var responsiveConfigService = $injector.get("responsiveConfigService");

/*COLUMNAS*/
var columns = [
{ key: "FN", headerText: "", dataType: "string", hidden: true }
, { key: "LF", dataType: "string", hidden: true }
, { key: "S", dataType: "string", hidden: true }
, { key: "MD", dataType: "string", hidden: true }
, { key: "ID", dataType: "string", hidden: true }
, { key: "CN", dataType: "string", hidden: true }
, { key: "D", headerText: "Denominación", width: "20%", dataType: "string" }
, { key: "F", headerText: "Fecha", width: "20%", dataType: "date", formatter: formatterService.fecha }
, { key: "LD", headerText: "Tipo de <br/> Movimiento", width: "10%", dataType: "string" }
, { key: "I", headerText: "Importe de la <br/>Operacion", dataType: "string", formatter: formatterService.inversionConSimbolo, template: templateService.generales.templateFor(['MS', 'I'], { acceptNull: false }), width: "10%" }
, { key: "IFP", headerText: "Importe Final <br/> del Periodo", dataType: "string", formatter: formatterService.inversionConSimbolo, width: "10%", template: templateService.generales.rightAlign('IFP') }
, { key: "CC", headerText: "Cantidad de Cuotapartes <br/> de la Operación", dataType: "string", width: "15%", template: templateService.generales.rightAlign('CC') }
, { key: "SC", headerText: "Saldo <br/> Cuotapartes", dataType: "string", formatter: formatterService.valorCantidadVCP, width: "10%", template: templateService.generales.rightAlign('SC') }
, {
headerText: "Resultado del Periódo",
group: [
{ key: "IP", headerText: "Importe", dataType: "string", template: templateService.generales.rightAlign('IP'), formatter: formatterService.inversionConSimbolo, width: "10%" }
, { key: "PP", headerText: "Porcentaje", dataType: "string",template: templateService.generales.rightAlign('PP'), formatter: formatterService.porcentaje, width: "10%" }
]
}
, { key: "IPS", headerText: "Importe", dataType: "string", formatter: formatterService.importeSinSimbolo, width: "5%", template: templateService.generales.rightAlign('IPS') }
, { key: "PPS", headerText: "Porcentaje", dataType: "string", formatter: formatterService.porcentaje, width: "7%", template: templateService.generales.rightAlign('PPS') }
, { key: "MasDatos", headerText: '', unbound: true, hidden: false, width: "6%", dataType: "", template: templateService.informerentabilidad.masDatos }
];

/*RESPONSIVE*/
var responsive = {
name: "Responsive",
responsiveSensitivity: 0,
reactOnContainerWidthChanges: true,
enableVerticalRendering: false,
responsiveModes: responsiveConfigService.responsiveModes,
columnSettings: [
{ columnKey: "D", configuration: responsiveConfigService.columnsShow.showSmMdLg },
{ columnKey: "F", configuration: responsiveConfigService.columnsShow.showSmMdLg },
{ columnKey: "I", configuration: responsiveConfigService.columnsShow.showSmLg },
{ columnKey: "IFP", configuration: responsiveConfigService.columnsShow.showSmLg },
{ columnKey: "CC", configuration: responsiveConfigService.columnsShow.showLg },
{ columnKey: "SC", configuration: responsiveConfigService.columnsShow.showLg },
{ columnKey: "IP", configuration: responsiveConfigService.columnsShow.showLg },
{ columnKey: "PP", configuration: responsiveConfigService.columnsShow.showLg },
{ columnKey: "IPS", configuration: responsiveConfigService.columnsShow.showSmMd },
{ columnKey: "PPS", configuration: responsiveConfigService.columnsShow.showSmMd },
{ columnKey: "MasDatos", configuration: responsiveConfigService.columnsShow.showSmMd }
]
};

function getTotalInversion(data) {
var ds = $("#gridReport").igGrid("option", "dataSource");
var sum = 0;
var simbolo = "";
$.map(ds, function (value) {
if (value.M == data) {
simbolo = value.S;
sum += value.LF;
}
});
return simbolo + " " + formatterService.importeSinSimbolo(sum);
}

function getImporte(data) {
var ds = $("#gridReport").igGrid("option", "dataSource");
var sum = 0;
var simbolo = "";
$.map(ds, function (value) {
if (value.M == data) {
console.log(value.PP);
simbolo = value.S;
sum += value.MD;
}
});
return simbolo + " " + formatterService.importeSinSimbolo(sum);
}

/*CARACTERISTICAS*/
var features = [
responsive,
{ name: 'MultiColumnHeaders' },
{
name: "GroupBy",
type: "local",
groupedRowTextTemplate: '${val}',
groupByAreaVisibility: "hidden",
columnSettings: [
{
columnKey: "CN",
isGroupBy: true
},
{
columnKey: "LF",
//groupLabelFormatter: function (val) {
// return val + "<div style='float:right'><b>" + getTotalInversion(val) + "</b></div>";
//},
isGroupBy: true
},
{
columnKey: "MD",
//groupLabelFormatter: function (val) {
// return val + "<div style='margin-left:1120px'><b>" + getImporte(val) + "</b></div>";
//},
isGroupBy: true
}

]
},
{ name: 'Resizing' },
{
name: 'Sorting',
columnSettings: [
{ columnKey: 'F', allowSorting: true}
, { columnKey: 'I', allowSorting: false }
, { columnKey: 'IFP', allowSorting: false }
, { columnKey: 'CC', allowSorting: false }
, { columnKey: 'SC', allowSorting: false }
, { columnKey: 'IP', allowSorting: false }
, { columnKey: 'PP', allowSorting: false }
, { columnKey: 'PPS', allowSorting: false }
]
}
];

/*MAS DATOS*/
var modal = function () {
return {
name: "Responsive",
responsiveSensitivity: 0,
enableVerticalRendering: true,
windowWidthToRenderVertically: Number.MAX_VALUE,
responsiveModes: { all: { minWidth: 0, maxWidth: Number.MAX_VALUE } },
columnSettings: [
{ columnKey: 'D', configuration: { all: { template: templateService.generales.rightAlign('D') } } },
{ columnKey: 'F', configuration: { all: { template: templateService.generales.rightAlign('F') } } },
{ columnKey: 'I', configuration: { all: { template: templateService.generales.rightAlign('I') } } },
{ columnKey: 'IFP', configuration: { all: { template: templateService.generales.rightAlign('IFP') } } },
{ columnKey: 'CC', configuration: { all: { template: templateService.generales.rightAlign('CC') } } },
{ columnKey: 'SC', configuration: { all: { template: templateService.generales.rightAlign('SC') } } },
{ columnKey: 'LD', configuration: { all: { template: templateService.generales.rightAlign('LD') } } },
//{ columnKey: 'IP', configuration: { all: { template: templateService.generales.rightAlign('IP') } } },
//{ columnKey: 'PP', configuration: { all: { template: templateService.generales.rightAlign('PP') } } },
//{ columnKey: 'IPS', configuration: { all: { template: templateService.generales.rightAlign('IPS') } } },
//{ columnKey: 'PPS', configuration: { all: { template: templateService.generales.rightAlign('PPS') } } },
{ columnKey: "MasDatos", configuration: { all: { hidden: true } } }
]
};
};

var gridOpts = {
primaryKey: "I",
columns: columns,
features: features,
dataSource: [],
autocommit: true,
dataSourceType: 'json',
width: "100%",
autoGenerateColumns: false,
autofitLastColumn: true,
enableUTCDates: true,
rowsRendered: function (evt, ui) {

$("#gridReport").igGrid('rows').each(function (index) {
var row = $("#gridReport").igGrid("rowAt", index);
var anulado;
if (row.cells.length > 2) {
$(row.cells).each(function (i) {
var cell = $("#gridReport").igGrid('cellAt', i, index);

var cellText = $(cell).text();
if (cellText == "Total Acum. Periodo")
{
anulado = "true";
}

if (i != 1 && i != 10 && i != 11 && anulado == "true") {
$(cell).text('');
}

});
}

});
}
};

var gridOptions = {
gridOpts: gridOpts,
responsive: modal,
};

return gridOptions;

}]);




  • 17590
    Offline posted

    Hello Lucas,

    Thank you for posting in our community.

    In order to initially sort igGrid by any column of your choice you can set the currentSortDirection option in columnSettings collection. If this setting is specified the column will be rendered sorted according to this option. For example:

    name: 'Sorting',
    columnSettings: [
    { columnKey: 'F', allowSorting: true,  currentSortDirection: "ascending" }
    , { columnKey: 'I', allowSorting: false }
    , { columnKey: 'IFP', allowSorting: false }
    , { columnKey: 'CC', allowSorting: false }
    , { columnKey: 'SC', allowSorting: false }
    , { columnKey: 'IP', allowSorting: false }
    , { columnKey: 'PP', allowSorting: false }
    , { columnKey: 'PPS', allowSorting: false }
    ]

    Additionally, if you would like to sort a column that is already rendered the sortColumn method can be used. It sorts the data in a grid column and updates the UI. For example:

    $(".selector").igGridSorting("sortColumn", "F", "descending");

    Please let me know if you need any further assistance with this matter.