vitalets / x-editable

In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
http://vitalets.github.io/x-editable
MIT License
6.51k stars 1.72k forks source link

How to Sort X-editable json data by values or stop default sorting by key #1109

Open lidiotduvillage opened 6 years ago

lidiotduvillage commented 6 years ago

Hello,

this is my editable code, jQuery('.billitemname').editable({ url: base_url+'timetracker/saveEdit', source: base_url+'/timetracker/getBillCats', type: 'select', mode: 'inline' });

and this is the Json data while i am getting in source,

{"96":"B2B Calling","68":"Billboards","12":"Comprehensive Planning","13":"Consulting Fees","109":"Content Writing","105":"Convenience Fee","15":"Creative Writing","104":"Digital Video X","55":"Direct Mail","62":"Direct Mail List","17":"Domain","98":"Drone Work","79":"Email Marketing","100":"Google Adwords","20":"Graphic Design","88":"Healthy Website Plan","89":"Healthy Website Plan Set up","21":"Logo Design","95":"Marketing Package","113":"Miscellaneous Marketing","103":"Mobile 360","83":"Online Ad","110":"Online Partnership Package - Brand Level","115":"Online Partnership Package - Strategy Level","97":"Onsite Tech","81":"Pay Per Click","94":"Photo Edits","25":"Photography","74":"Postage","26":"Print Ad","27":"Print Work","101":"Production","93":"Production Supplies","67":"Promotional Items","30":"Radio Ads","28":"Radio Production","114":"Research","102":"Retargeting","90":"Robo Calls","87":"Services","34":"Shipping","35":"Signage","80":"Social Media Marketing","75":"SSL Certificate","91":"Stock Photography","107":"Talent Fees","73":"Trade","37":"TV Ads","38":"TV production Cost","56":"Video Work","92":"Video\/Social Package","51":"Voice Talent","40":"Web Hosting","33":"Web Optimization","84":"Web Work","46":"Website Design"}

But it is sorting by default key, So my output is like ..... so on,

lidiotduvillage commented 6 years ago

Is there someone who could help ? thank you

lidiotduvillage commented 6 years ago

Here comes a solution to set around line 2797 ` var arrayForm = []; Object.keys(data).forEach(function(key) { arrayForm.push({ key: key, value: data[key] }); });

            arrayForm = arrayForm.sort(function(a, b) {
                return a.value.localeCompare(b.value);
            });

            arrayForm.forEach(function(arrayData) {

                result.push({
                    value: arrayData.key,
                    text: arrayData.value
                });
            });
            // $.each(data, function (k, v) {
            //     result.push({value: k, text: v});
            // });  `