jQWidgets Forums

jQuery UI Widgets Forums DataTable Localization object multiplies values of first line

This topic contains 9 replies, has 2 voices, and was last updated by  Peter Stoev 10 years, 4 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author

  • Florian Auer
    Participant

    Hi

    I#ve created a DataTable with 2 extra cellrenderers to display a symbol instead of the value.
    Also i wanted to add a localisation object to it, for language specific output.

    The interesting thin is:
    If i activate this feature by setting the localization property like localization: getLocalization()
    The data of the first line in the table is displayed with the values multiplied by 10 or even more.

    example:
    146.349042 becomes 146.349.042,00
    But only the first line… all other lines are formatted correctly

    
    var getLocalization = function () {
    	var localizationobj = {};
    	localizationobj.pagerGoToPageString = "Gehe zu:";
    	localizationobj.pagerShowRowsString = "Zeige Zeile:";
    	localizationobj.pagerRangeString = " von ";
    	localizationobj.pagerNextButtonString = "voriger";
    	localizationobj.pagerFirstButtonString = "first";
    	localizationobj.pagerLastButtonString = "last";
    	localizationobj.pagerPreviousButtonString = "nächster";
    	localizationobj.sortAscendingString = "Sortiere aufsteigend";
    	localizationobj.sortDescendingString = "Sortiere absteigend";
    	localizationobj.sortRemoveString = "Entferne Sortierung";
    	localizationobj.firstDay = 1;
    	localizationobj.percentSymbol = "%";
    	localizationobj.currencySymbol = "€";
    	localizationobj.currencySymbolPosition = "after";
    	localizationobj.decimalSeparator = ",";
    	localizationobj.thousandsSeparator = ".";
    	var days = {
    		// full day names
    		names: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
    		// abbreviated day names
    		namesAbbr: ["Sonn", "Mon", "Dien", "Mitt", "Donn", "Fre", "Sams"],
    		// shortest day names
    		namesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]
    	};
    	localizationobj.days = days;
    	var months = {
    		// full month names (13 months for lunar calendards -- 13th month should be "" if not lunar)
    		names: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", ""],
    		// abbreviated month names
    		namesAbbr: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dez", ""]
    	};
    	localizationobj.months = months;
    	var patterns = {
    		d: "dd.MM.yyyy",
    		D: "dddd, d. MMMM yyyy",
    		t: "HH:mm",
    		T: "HH:mm:ss",
    		f: "dddd, d. MMMM yyyy HH:mm",
    		F: "dddd, d. MMMM yyyy HH:mm:ss",
    		M: "dd MMMM",
    		Y: "MMMM yyyy"
    	}
    	localizationobj.patterns = patterns;
    	return localizationobj;
    }
    

    Has someone an idea for this?
    Any help welcome


    Peter Stoev
    Keymaster

    Hi DesMas,

    Could you provide a full example which demonstrates such behavior?

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Florian Auer
    Participant

    Hi

    I tried to get a JSFiddle example to work with the code extracted from the project.
    But it seems every time my data object has more than one item, the table in the example does not load;
    http://jsfiddle.net/v7pz74kz/18/

    hmmm.. i don’t get behind this….inside the project it loads correctly


    Peter Stoev
    Keymaster

    Hi DesMas,

    The provided fiddle uses API like toFormattedString and had a syntax error. I don’t know what is toFormattedString – may be it comes from additional script which you missed to load. However, I corrected these and updated the fiddle: http://jsfiddle.net/jqwidgets/ghgq6et0/

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Florian Auer
    Participant

    Hi Peter

    Yes just noticed, that i missed to add two prototype extensions for the Number object 🙂

    http://jsfiddle.net/v7pz74kz/20/

    Interesting for me is:
    – when i stop inside the cellRenderer, rowData.format is “0” but should be “0.00” as given i the first JSON object ?!
    – the second stop for the second array entry shows the format correctly as “0.00”
    – may this have something to do with my problem?

    
    cellsRenderer: function (row, column, value, rowData)
    		        	{
    		        		if(rowData.format != ""){
    		        			var n = rowData.ist;
    		        			if(!isNaN(n)){
    		        				n = new Number(n);
    		        			}
    		        			return n.toFormattedString(rowData.format);
    		        		}else{
    		        			return value;
    		        		}
    		        	}
    

    Peter Stoev
    Keymaster

    Hello DesMas,

    why do you think it should be “0.00”? Don’t you want it to be number? Also, dataFields – where is that array in the provided code? It is mandatory and should be always set.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Florian Auer
    Participant

    Hello Peter

    Thx for your reply

    Short description at first:
    The table i wanted to create should have values of multiple formats (number, date, currency, …) within the same column. That was the reason to put a format description into the data and let the cell renderer then build the formatted value out of the entry.
    This seems to work for all rows except the first one.

    The format definition for the first entry should be “0.00” beause the source array for the kpi “Girokonteneröffnungen/MAK” has this definition:

    
        {   
            trend:"1",
            stateSoll:true,
            infotext:"",
            kennzahl:"Girokonteneröffnungen/MAK",
            gewichtung:20,
            bewertung:3,
            id:84,
            soll:0.719,
            format:"0.00",
            gruppe:"BOF2",
            ist:0.197097,
            abweichung:72.58734353268429
        }
    

    The dataFields array itself is defined inside the buildKpiTable function (old version, new example updated):

    
    var source =
        {
            datatype: "json",
            datafields: [
                { name: 'kennzahl' },
                { name: 'bewertung' },
                { name: 'trend' },
                { name: 'ist' },
                { name: 'soll' },
                { name: 'abweichung' },
                { name: 'gewichtung' },
                { name: 'format' }
            ],
            localdata: fSettings.data
        };
    if(fSettings.showInfoText){
    	source.datafields.push({name: 'infotext'});
    }
    var dataAdapter = new $.jqx.dataAdapter(source);
    

    The idea behind this was to define a function that builds the table with all specifications and later on change the data multiple times due the user interaction.
    Therefor i thought a short definition of the new data adapter like

    
    var source = {
        datatype: "json",
        localdata: data
    };
    $("#kzTabelle").jqxDataTable({
        source: new $.jqx.dataAdapter(source)
    }); 
    

    would be enough can i can omitt the dataFields array in this.

    I changed the code now, so the dataFields array is always defined with all entries: http://jsfiddle.net/v7pz74kz/23/
    But the format for the first row is stil not taken into account, i must have done it wrong :).


    Peter Stoev
    Keymaster

    Hi DesMas,

    Actually, the first definition is not correct, too. The “type” which is mandatory setting is missing.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Florian Auer
    Participant

    Hi Peter

    Thx again for the fast reply

    I think that is it… I took the JSOn definition from the Data sources example at http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdatatable/jquery-datatable-data-sources.htm where the source also does not define the type and thought that this would work correctly.

    provided example:

    
    // prepare the data
    var source =
    {
        dataType: "json",
        dataFields: [
            { name: 'empName' },
            { name: 'age' },
            { name: 'id', map: 'department>id' },
            { name: 'name', map: 'department>name' },
            { name: 'author' }
        ],
        localData: data
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    

    fixed result: http://jsfiddle.net/v7pz74kz/24/


    Peter Stoev
    Keymaster

    Hi DesMas,

    Oh, you found the only sample which does not define these. Ok, it’s our issue that we missed to update this. I confirm that and sorry if I mislead you with something. The specific one was for demonstrating how to implement Mapping, not Binding. I would suggest you to look also the available demos.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.