Click here to Skip to main content
14,303,639 members

JavaScript

 
QuestionCreating a JScript to add the filename to a document in PDF-Exchange Editor. Pin
MisterBobTheTomato18-Sep-19 2:32
memberMisterBobTheTomato18-Sep-19 2:32 
QuestionWhat is J Query in Javascript Pin
Jack Smiths13-Sep-19 6:49
memberJack Smiths13-Sep-19 6:49 
AnswerRe: What is J Query in Javascript Pin
Richard Deeming13-Sep-19 7:01
mveRichard Deeming13-Sep-19 7:01 
GeneralRe: What is J Query in Javascript Pin
microrama0120-Sep-19 2:11
membermicrorama0120-Sep-19 2:11 
AnswerRe: What is J Query in Javascript Pin
ZurdoDev16-Sep-19 4:00
professionalZurdoDev16-Sep-19 4:00 
QuestionSorting an array in typescript, based on a search query Pin
jkirkerx6-Sep-19 7:31
professionaljkirkerx6-Sep-19 7:31 
So I created this user interface to manage the sub categories of a category.
I have the whole document loaded in Angular V7+ as a model, and I just list the sub categories in a table.

Now I have a search interface in which I'd like to query to sub categories to find a specific one.
In all my other uses of search, I call a service to .Net Core and let core find the answer and return them. Well that's easy because I'm loading documents. But this time I'd like to just search the model in the DOM. In other words find the data within the document. This way I can edit the document and return the whole document upon a change and let Core update it.

So I can find the Sub Category, but I'd like to reorder the array. Show the search results first and then the rest in TypeScript. Right now I'm just loading the result in a Modal UI for editing. But I will run into this in the future so I should figure it out.

Not sure if I'm approaching this right or not as far as my document design goes. Of if it's not feasible to do and I should write a service for it and let Core do the work.

I looked at this javascript - Reordering arrays - Stack Overflow. I can sort the list, and splice, but this is more complicated to me.

By the way, result just returns 1 record even if 2 exists.

eg.
{
    "_id" : "5d702eab43c22b1674a8e680",
    "Name" : "SSD Drives",
    "Description" : "Solid State Hard Drives",
    "Image" : {
        "_id" : null,
        "Name" : null,
        "Alt" : null,
        "Data" : null,
        "Base64" : null,
        "Url" : null,
        "Type" : null
    },
    "CreatedBy" : "admin",
    "CreatedOn" : ISODate("2019-09-04T21:37:47.331Z"),
    "UpdatedOn" : ISODate("2019-09-06T16:58:16.464Z"),
    "Selected" : false,
    "SubCategories" : [ 
        {
            "_id" : "5d717a48675cc0229cf15ee5",
            "Name" : "SATA",
            "Description" : "2 1/2\" Sata 3 Drive",
            "CreatedBy" : "admin",
            "CreatedOn" : ISODate("2019-09-05T21:12:41.633Z"),
            "UpdatedOn" : ISODate("2019-09-05T21:12:18.721Z"),
            "Selected" : false
        }, 
        {
            "_id" : "5d717b54c4653d1c24753241",
            "Name" : "PCIe",
            "Description" : "PCI Addon Card with NVMe",
            "CreatedBy" : "admin",
            "CreatedOn" : ISODate("2019-09-05T21:17:08.370Z"),
            "UpdatedOn" : ISODate("2019-09-05T21:17:04.806Z"),
            "Selected" : false
        }, 
searchSubCategories() {

  this.query = this.subCategoriesForm.controls["searchQuery"].value;
  if (this.query) {
    const result = this.model.SubCategories
      .find(q => q.Name.toLowerCase().includes(this.query.toLowerCase(), 0)
        || q.Description.toLowerCase().includes(this.query.toLowerCase(), 0));
    if (result) {
      this.subCategoryEditorForm.controls["subCategoryId"].setValue(result.Id);
      this.subCategoryEditorForm.controls["subCategoryEditorMode"].setValue("EDIT");
      this.subCategoryEditorForm.controls["name"].setValue(result.Name);
      this.subCategoryEditorForm.controls["description"].setValue(result.Description);
      this.subCategoryEditorForm.controls["createdBy"].setValue(result.CreatedBy);
      this.subCategoryModal.show();
    }
  }
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Sorting an array in typescript, based on a search query Pin
jkirkerx18-Sep-19 13:37
professionaljkirkerx18-Sep-19 13:37 
GeneralRe: Sorting an array in typescript, based on a search query Pin
Nathan Minier19-Sep-19 1:37
professionalNathan Minier19-Sep-19 1:37 
GeneralRe: Sorting an array in typescript, based on a search query Pin
jkirkerx19-Sep-19 7:18
professionaljkirkerx19-Sep-19 7:18 
GeneralRe: Sorting an array in typescript, based on a search query Pin
Nathan Minier19-Sep-19 7:24
professionalNathan Minier19-Sep-19 7:24 
GeneralRe: Sorting an array in typescript, based on a search query Pin
jkirkerx19-Sep-19 9:16
professionaljkirkerx19-Sep-19 9:16 
QuestionJavascript object comparison Pin
Anandkumar Prajapati28-Aug-19 19:24
professionalAnandkumar Prajapati28-Aug-19 19:24 
AnswerRe: Javascript object comparison Pin
Richard MacCutchan28-Aug-19 21:32
protectorRichard MacCutchan28-Aug-19 21:32 
GeneralRe: Javascript object comparison Pin
A_Griffin22hrs 5mins ago
memberA_Griffin22hrs 5mins ago 
GeneralRe: Javascript object comparison Pin
Richard MacCutchan12hrs 31mins ago
protectorRichard MacCutchan12hrs 31mins ago 
QuestionCopying Text from Web Message Box/pop-Up Window Pin
Member 1456795025-Aug-19 2:07
memberMember 1456795025-Aug-19 2:07 
AnswerRe: Copying Text from Web Message Box/pop-Up Window Pin
Richard MacCutchan25-Aug-19 4:25
protectorRichard MacCutchan25-Aug-19 4:25 
QuestionHow do I a value from one function and pass it through to another for use Pin
Member 1028754813-Aug-19 11:13
memberMember 1028754813-Aug-19 11:13 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
Richard MacCutchan13-Aug-19 21:33
protectorRichard MacCutchan13-Aug-19 21:33 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
rinave19-Aug-19 15:58
memberrinave19-Aug-19 15:58 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:36
professionalZurdoDev21-Aug-19 5:36 
GeneralRe: How do I a value from one function and pass it through to another for use Pin
Richard Deeming21-Aug-19 8:26
mveRichard Deeming21-Aug-19 8:26 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:35
professionalZurdoDev21-Aug-19 5:35 
QuestionComparison's in JavaScript Pin
BobInNJ7-Aug-19 10:57
memberBobInNJ7-Aug-19 10:57 
AnswerRe: Comparison's in JavaScript Pin
ZurdoDev7-Aug-19 11:10
professionalZurdoDev7-Aug-19 11:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.