diff --git a/biosys/apps/main/models.py b/biosys/apps/main/models.py index 6d388a2a..4fb82c6d 100644 --- a/biosys/apps/main/models.py +++ b/biosys/apps/main/models.py @@ -126,6 +126,10 @@ class AbstractRecord(models.Model): def __str__(self): return "{0}: {1}".format(self.dataset.name, Truncator(self.data).chars(100)) + @property + def data_with_id(self): + return dict({'id': self.id}, **self.data) + class Meta: abstract = True diff --git a/biosys/apps/publish/static/js/data_view.js b/biosys/apps/publish/static/js/data_view.js index 728749be..b4e83a7e 100644 --- a/biosys/apps/publish/static/js/data_view.js +++ b/biosys/apps/publish/static/js/data_view.js @@ -80,22 +80,35 @@ biosys.view_data = function ($, _, moduleOptions) { headers = _.map(ds.data_package.resources[0].schema.fields, function (field) { return field.name; }); + // add the hidden id column + colDefs = _.map(headers, function (header) { return { - 'title': header, - 'name': header, - 'data': header + title: header, + name: header, + data: header }; }); + // add the hidden id column at the first place + colDefs.unshift( + { + title: 'id', + name: 'id', + data: 'id', + visible: false + } + ); url = '/publish/data/' + ds.id; - tableOptions = $.extend({}, defaultTableOptions, { + tableOptions = $.extend({ + order: [[0, 'asc']] // sort by id + }, defaultTableOptions, { ajax: { url: url, method: 'get', error: function (xhr, textStatus, thrownError) { console.log("Error while loading applications data:", thrownError, textStatus, xhr.responseText, xhr.status); //Stop the data table 'Processing'. - //$(options.selectors.applicationsTable + '_processing').hide(); + //$(options.selectors.table + '_processing').hide(); } } }); @@ -109,7 +122,6 @@ biosys.view_data = function ($, _, moduleOptions) { return { init: function () { initProjectFilter(); - //$('select').select2(); } }; }; diff --git a/biosys/apps/publish/views/data_view.py b/biosys/apps/publish/views/data_view.py index 3ab85cc1..ee06a737 100644 --- a/biosys/apps/publish/views/data_view.py +++ b/biosys/apps/publish/views/data_view.py @@ -19,18 +19,18 @@ def get_context_data(self, **kwargs): class JSONDataTableView(LoginRequiredMixin, View): - def get(self, reuest, *args, **kwargs): + def get(self, request, *args, **kwargs): ds = get_object_or_404(DataSet, pk=kwargs.get('pk')) rows = [] records = GenericRecord.objects.filter(dataset=ds) for record in records: - rows.append(record.data) + rows.append(record.data_with_id) records = Observation.objects.filter(dataset=ds) for record in records: - rows.append(record.data) + rows.append(record.data_with_id) records = SpeciesObservation.objects.filter(dataset=ds) for record in records: - rows.append(record.data) + rows.append(record.data_with_id) return JsonResponse({ 'data': rows })