How to apply "where" to a joined table in jQuery Editor Configuration

How to apply "where" to a joined table in jQuery Editor Configuration

rdmrdm Posts: 192Questions: 54Answers: 4

In a different question, I learned how to filter by value on the client side in this manner.

ajax: {
    url: "@Url.Action("Table1")",
    data: function ( d ) {
        d.campus = "@Model.Campus";
        d.teacher = "@Model.Teacher";
    },
    type: "POST"
},

But suppose I have a joined table, where I need to filter by Table1.Campus or Table2.StudentId. How would I indicate that in dot notation, like d.campus?

I tried d.FridayPlanningRoster.Campus = "@Model.Campus"; and got an error of Uncaught TypeError: Cannot set property 'Campus' of undefined. I figured that wouldn't work, but I tried anyway.

I originally had the where commands on the server side, but my edited rows would vanish, hence moving the filters to the jQuery configuration block.

How should I change my data function so that I can apply what is really this: d.FridayPlanningRoster.Campus = "@Model.Campus"?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓
    d.FridayPlanningRoster = {};
    d.FridayPlanningRoster.Campus = "@Model.Campus";
    

    Allan

  • rdmrdm Posts: 192Questions: 54Answers: 4

    Where in the documentation can I read more about this.

  • rdmrdm Posts: 192Questions: 54Answers: 4

    @Allan -- I'm searching through the documentation, trying to find more explanation of the example you show above and I am not able to find anything relevant. Perhaps I'm not using the correct keywords?

    In any case, I'm trying to convert what I used on the server side and have two cases that I am unable to convert (so far) into something usable on the client-side config section.

    Do you have any documentation that can further instruct on cases like this?

    Case #1: where record field is in an array:

        .Where(q => q.Where("WeekList.WeekDescription", weeks, "IN", false))
    
    

    Case #2: where record field is in an optional array.

        .Where(q =>
        {
            if (students == "()") return;
            q.Where("FridayPlanningRosterMembers.StudentId", students, "IN", false);
        })
    
  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Where in the documentation can I read more about this.

    That's a generic Javascript thing - nothing specific to DataTables or Editor. It would apply anywhere in Javascript. You need to create an object before you can attach something to it. You won't find anything specifically about that in the DataTables / Editor documentation, nor do I believe that there should be to be honest.

    In any case, I'm trying to convert what I used on the server side and have two cases that I am unable to convert (so far) into something usable on the client-side config section.

    I'm not quite clear on what the goal is here I'm afraid. Do you want to apply those Where filters on the client-side?

    Allan

  • rdmrdm Posts: 192Questions: 54Answers: 4
    edited October 2017

    Understood. What I'm trying to do is work out a solution that might be considered an edge case for Editor.

    I was dealing with the same "record vanishes when edited" symptom. The technique I learned from you in another response was to not use the .Where() filter on the server but rather put it in the jQuery block. For simple cases, like campus = "@Model.Campus", it works great, but in cases where a field is the result of a function or a nested function, I was able to work out a solution on the server, but not in the jQuery block.

    Yesterday, I stumbled into a workaround that allows me to keep my .Where() filters on the server. By not having any readonly columns, I don't have the vanishing row symptom anymore. I'm still trying to work out a way to prevent the user from not editing read-only fields, but it seems to work.

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    The technique I learned from you in another response was to not use the .Where() filter on the server but rather put it in the jQuery block.

    I'll just clarify that in case anyone else reads this: what we discussed before what the the DataTables Ajax request sent data to the server which would be applied to the WHERE condition. Editor wasn't sending that data - adding it to ajax.data resolve that.

    it works great, but in cases where a field is the result of a function or a nested function, I was able to work out a solution on the server, but not in the jQuery block.

    How is this working for the DataTables data fetch request, but not the Editor submit? What are you submitting to the server for the data fetch that is different and what is the processing that is used?

    Another option is to simply not use .Where() when a create/edit/remove request is made, but I think resolving the question above would probably be a better solution.

    Allan

  • rdmrdm Posts: 192Questions: 54Answers: 4

    @allan --

    "How is this working for the DataTables data fetch request, but not the Editor submit?"

    That's a good question that I don't know how to answer. I've looked at browser network traces, jQuery traces, and controller traces. I can't find find the code that causes the problem. I'm making myself walk away from it for a couple of days. Maybe something might click for me then.

This discussion has been closed.