jQWidgets Forums

jQuery UI Widgets Forums Grid JqxGrid row number due to another column.

This topic contains 2 replies, has 2 voices, and was last updated by  Franco01 8 years, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • JqxGrid row number due to another column. #87303

    Franco01
    Participant

    Hi!

    I can’t solved the following problem.
    I need a row number, which depends on Date column. If Date is not equal than previous Date, than row number start again with 1.

    `columns:
    [
    {
    text: “Date”, dataField: “Date”,
    columntype: “datetimeinput”,
    align: ‘center’,
    formatString: “yyyy.MM.dd”,
    cellsFormat: ‘yyyy.MM.dd’,
    width: 120,
    createeditor: function (row, cellvalue, editor) {
    editor.jqxDateTimeInput({ culture: “hu-HU”, formatString: “yyyy.MM.dd” });
    }
    },
    {
    text: “RowNumber”,
    cellsalign: “right”,
    sortable: false,
    filterable: false,
    editable: false,
    groupable: false,
    draggable: false,
    resizable: false,
    datafield: “”,
    columntype: “number”,
    width: 70,
    cellsrenderer: function (row, column, value) {
    var rownumber;
    if (row != 0) {
    var prevdate = $(“#jqxgrid”).jqxGrid(“getcelltext”, row – 1, “Date”);
    var date = $(“#jqxgrid”).jqxGrid(“getcelltext”, row, “Date”);
    if (prevdate == date) {
    rownumber= $(“#myForm”).data(“rownumber”);
    rownumber= rownumber+ 1;
    } else
    rownumber= 1;
    } else
    rownumber= 1;
    $(“#myForm”).attr(“data-rownumber”, rownumber);
    return “<div style=’margin:4px;’>” + rownumber+ “</div>”;
    }
    }`

    Example
    Date RowNumber
    2016.04.20 1
    2016.04.20 2
    2016.04.20 3

    My Code works:
    Date RowNumber
    2016.04.20 1
    2016.04.20 2
    2016.04.20 2

    because in this line, I get 1 in the rownumber variable from myForm data rownumber attribute.
    rownumber= $("#myForm").data("rownumber");

    JqxGrid row number due to another column. #87324

    Hristo
    Participant

    Hello Franco01,

    It is simple mistake need to declare out of the Grid initialization and could you try this:

    var rownumber = 1;
    $("#jqxgrid").jqxGrid(
    	{
    		...
    		columns: [
    			{ ... },
    			{
    				text: "RowNumber",
    				...				
    				cellsrenderer: function (row, column, value)
    				{
    					if (row != 0)
    					{
    						var prevdate = $("#jqxgrid").jqxGrid("getcelltext", row - 1, "Date");
    						var date = $("#jqxgrid").jqxGrid("getcelltext", row, "Date");
    						// .. add your logic
    						if (prevdate == date)
    						{
    							rownumber += 1;
    						} else
    						{
    							rownumber = 1;
    						}
    					}
    
    					return "<div style='margin:4px;'>" + rownumber + "</div>";
    				}
    			}
    		]
    });

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    JqxGrid row number due to another column. #87349

    Franco01
    Participant

    Of course! Thank you!:)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.