Answered by:
Sort title by alphabetical order

Question
-
User-501297529 posted
I'm not sure where to sort the title at, would that be at the view level or in the repository?
i tried setting it in the repository but that doesn't seem to work
public IEnumerable<DocumentEntity> FindPoliciesDocuments() { return DbContext .Set<DocEntity>() .Include(d => d.EgendaFile) .Where(d => d.EgendaDocumentTypeEntity.Id == (int)EgendaDocumentType.Policies) .Where(d => d.IsDeleted == false || d.IsDeleted == null).AsEnumerable() .OrderBy(d => d.Title); }
View which sorts by title but it doesn't sort in alphabetical order. This is in a partial view, could that be the issue?
<div class="tab-container"> <table id="documentsTable_@Model.Source" class="table table-striped table-bordered display responsive nowrap" style="width: 100%"> <thead> <tr> @{ if (!@Model.IsUserView) { <th class="all">Action</th> } else { <th class="all th-hide-column"></th> } } <th class="all">Title</th> <th class="all">Date</th> </tr> </thead> <tbody> @foreach (var document in Model.Documents.OrderBy(d => d.Title)) { <tr id="row_@document.Id"> @{ if (!@Model.IsUserView) { <td> <a data-toggle="modal" data-id=@document.Id data-documentType="@Model.Source" data-target="#delete-document-modal" class="btn btn-danger delete-document"> <i class="fa fa-trash fa-fw" title="Delete" style="color: white"></i> </a> <a asp-controller="Document" asp-action="EditDocument" asp-route-id="@document.Id" asp-route-documentType="@Model.Source" class="btn btn-info"> <i class="fa fa-pencil fa-fw" title="Edit" style="color: white"></i> </a> <a id="view-packet-item-file" class="btn btn-secondary" target="_blank" asp-area="" asp-controller="File" asp-action="Download" asp-route-documentId="@document.Id" asp-route-source="@Model.Source"> <i class="fa fa-file-pdf-o fa-fw" aria-hidden="true" title="View" style="color: black"></i> </a> </td> <td>@document.Title</td> } else { <td class="td-hide-column"></td> <td> @{ if (@document.EgendaFile == null) { } } <a id="view-packet-item-file" asp-area="" asp-controller="File" asp-action="DownloadFile" asp-route-fileId="@document.EgendaFile?.Id" target="_blank"> @document.Title </a> </td> } } <td data-order="@sortingDate">@document.Date.ToString("d")</td> } </tr> } </tbody> </table> </div>
Tuesday, May 5, 2020 7:29 PM
Answers
-
User-501297529 posted
bootzilla
I think I may have figured it out. Since title is the first column I set this to 0 instead of 2 and it worked. Is that the only thing I need to change?
"order": [[0, "desc"]],
I'm not sure. I can't see all the relevant code.
What do you need to see that I haven't already posted?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 6, 2020 3:30 PM
All replies
-
User475983607 posted
I'm not sure what you mean by "sorts by title but it doesn't sort in alphabetical order". What is the sort order?
Sorting is a UI function. Normally, sorting happens in an Action or Razor Page right before displaying the records.
Have you tried view the list order in the debugger? Have you implemented client side sorting?
Tuesday, May 5, 2020 8:38 PM -
User-501297529 posted
I'm not sure what you mean by "sorts by title but it doesn't sort in alphabetical order". What is the sort order?
Sorting is a UI function. Normally, sorting happens in an Action or Razor Page right before displaying the records.
Have you tried view the list order in the debugger? Have you implemented client side sorting?
The sort order is by title so it should sort in alphabetical order of each title.
I have tried it in the debugger and it shows each time throw the foreach loop in alphabetical order but it isn't displaying on the browser page.
Tuesday, May 5, 2020 8:45 PM -
User475983607 posted
The sort order is by title so it should sort in alphabetical order of each title.
I have tried it in the debugger and it shows each time throw the foreach loop in alphabetical order but it isn't displaying on the browser page.
Can you share the object model? I assume EgendaFile is a Collection within DocEntity.
Tuesday, May 5, 2020 9:31 PM -
User-501297529 posted
mgebhard
bootzilla
The sort order is by title so it should sort in alphabetical order of each title.
I have tried it in the debugger and it shows each time throw the foreach loop in alphabetical order but it isn't displaying on the browser page.
Can you share the object model? I assume EgendaFile is a Collection within DocEntity.
Here is the data model and domain model.
public class Document : ModelBase { /// <summary> /// Gets or sets a specific/unique ID for a certain item /// </summary> public long Id { get; set; } /// <summary> /// Gets the value of documentId and decides if its new or not /// </summary> public bool IsNew => Id == 0; /// <summary> /// Gets or sets the document date /// </summary> public DateTime Date { get; set; } /// <summary> /// Gets or sets a specific Title for am Item (Varchar) /// </summary> /// public string Title { get; set; } /// <summary> /// Gets or sets whether a certain item was deleted or not (Boolean) /// </summary> public bool? IsDeleted { get; set; } /// <summary> /// Gets or sets the date of deletion /// </summary> public DateTime? DeletionDate { get; set; } /// <summary> /// Gets or sets the Egenda file /// </summary> public EgendaFile EgendaFile { get; set; } /// <summary> /// Gets or sets the File Id /// </summary> public long FileId { get; set; } }
public class DocumentEntity : EntityBase, IAggregateRoot { /// <summary> /// Gets or sets a specific/unique ID for a certain item (Primary Key --> Integer) /// </summary> public long Id { get; set; } /// <summary> /// Gets or sets the document date /// </summary> public DateTime Date { get; set; } /// <summary> /// Gets or sets a specific Title for am Item (Varchar) /// </summary> /// public string Title { get; set; } /// <summary> /// Gets or sets whether a certain item was deleted or not (Boolean) /// </summary> public bool? IsDeleted { get; set; } /// <summary> /// Gets or sets the date of deletion /// </summary> public DateTime? DeletionDate { get; set; } /// <summary> /// Gets or sets the Egenda File Entity for each document /// </summary> [ForeignKey("DocumentFileId")] public EgendaFileEntity EgendaFile { get; set; } [ForeignKey("FK_EgendaFile_EgendaDocumentType_Id")] public EgendaDocumentTypeEntity EgendaDocumentTypeEntity { get; set; } }
A thing I noticed is when I look at this in the browser it seems that it orders the title by the highest number date. That's the best way I can explain it. It looks like this:
Title Date
Supervisor's 4/6/2020
2020 Board Committee 4/5/2020
2020 Chairman Committee 4/17/2020
Member's Committee 4/1/2020If I change that Supervisor's to 3/6/2020 it looks like this
Title Date
2020 Board Committee 4/5/2020
2020 Chairman Committee 4/17/2020
Member's Committee 4/1/2020
Supervisor's 3/6/2020
Seems like the date is taking precedence for some reason.
Tuesday, May 5, 2020 10:43 PM -
User475983607 posted
Seems like the date is taking precedence for some reason.What's this?
<td data-order="@sortingDate">@document.Date.ToString("d")</td>
Do you have a JavaSctipt libraries that is sorting the table results?
Wednesday, May 6, 2020 10:11 AM -
User-501297529 posted
mgebhard
bootzilla
Seems like the date is taking precedence for some reason.What's this?
<td data-order="@sortingDate">@document.Date.ToString("d")</td>
Do you have a JavaSctipt libraries that is sorting the table results?
That used to be there but I removed it from the code.
Here is my javascript
function loadDirectors() { if (!$.fn.dataTable.isDataTable('#documentsTable_Directors')) { $('#documentsTable_Directors').DataTable({ "columnDefs": [ { orderable: false, targets: 0 }, { className: "dt-left width-90 text-wrap", targets: 1 }, { className: "dt-left text-wrap", targets: 2 } ], "order": [[2, "desc"]], "responsive": { details: { type: 'column', target: 'tr' } }, "language": { "emptyTable": "No Director's documents." } }); } }
I think I may have figured it out. Since title is the first column I set this to 0 instead of 2 and it worked. Is that the only thing I need to change?
"order": [[0, "desc"]],
Wednesday, May 6, 2020 2:51 PM -
User475983607 posted
I think I may have figured it out. Since title is the first column I set this to 0 instead of 2 and it worked. Is that the only thing I need to change?
"order": [[0, "desc"]],
I'm not sure. I can't see all the relevant code.
Wednesday, May 6, 2020 3:00 PM -
User-501297529 posted
bootzilla
I think I may have figured it out. Since title is the first column I set this to 0 instead of 2 and it worked. Is that the only thing I need to change?
"order": [[0, "desc"]],
I'm not sure. I can't see all the relevant code.
What do you need to see that I haven't already posted?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 6, 2020 3:30 PM -
User475983607 posted
What do you need to see that I haven't already posted?How can I possibly know the answer to this question?
We can only see the code that you shared on the forum. Your first post mentioned nothing about using a DataTable which has sorting capabilities. I even asked if you were using a JavaScript library.
I recommend making the changes and testing. Debug if the code does not work as expected. If you want community support than i is up to you to share enough code to reproduce the issue.
Wednesday, May 6, 2020 3:48 PM -
User475983607 posted
I'm curious. Did fixing the DataTable configuration solve the sorting issue or did you make updates to another script?Wednesday, May 6, 2020 8:10 PM