Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flourgirl's avatar

How do I reload only the table data with Laravel/Inertia/Vue

I have an orders page where, when the page loads, today's orders are shown in the table and today's date is displayed

<div>
        <h1>Showing Orders For</h1>
    </div>

    <div>
        <p>{{ selectedDates.start_date }}</p><span>TO</span>
        <p>{{ selectedDates.end_date }}</p>
    </div>

    <div>
        <p>Select New dates:</p>
        <input type="date"
               name="start_date"
               id="start_date"
               v-model="selectedDates.start_date">
        <span>TO</span>
        <input type="date"
               name="end_date"
               id="end_date"
               v-model="selectedDates.end_date">
        <PrimaryButton type="button" @click="updateDates">Update</PrimaryButton>
    </div>
    <tbody>
            <tr v-for="order in orderDetails"
                :key="order.id">
                <td>{{ order.order.order_date }}</td>
                <td>{{ order.order.order_time }}</td>
                <td>{{ order.order.customer.first_name }}</td>
                <td>{{ order.order.customer.last_name }}</td>
                <td>{{ order.order.customer.company?.company_name ?? '' }}</td>
            </tr>
    </tbody>
<script setup>
const orderDetails = ref(props.orderDetails);
const selectedDates = reactive({
    start_date: orderDetails.start_date || new Date().toISOString().substr(0, 10),
    end_date: orderDetails.end_date || new Date().toISOString().substr(0, 10),
});
function fetchOrderDetails() {
    router.get('/', selectedDates)
}
function updateDates() {
    fetchOrderDetails();
}
</script>
public function index(Request $request)
   {
       $start_date = $request->input('start_date'); 
       $end_date = $request->input('end_date'); 
       $orderDetails = OrderDetail::join('orders', 'order_details.order_id', '=', 'orders.id')
           ->with('product', 'order.customer.company')
           ->whereBetween('orders.order_date', [$start_date, $end_date])
           ->groupBy('order_details.order_id')
           ->orderBy('orders.order_date')
           ->get();
           return Inertia::render('Dashboard', [
           'orderDetails' => $orderDetails,
       ]);
   }

The orders load correctly when new dates are selected - but the dates keep going back to today's date. How do I get the dates to only reset when the user selects new dates? I've messed with partial page reloads, but haven't gotten anything to work.

0 likes
8 replies
flourgirl's avatar

It reply to the Bot - I'm trying to use Inertia - not Axios. Isn't there a way to do it with Inertia?

flourgirl's avatar

@Ben Taylor I get an 'invalid watch source'

const selectedDates = useRemember({
    start_date: orderDetails.start_date || new Date().toISOString().substr(0, 10),
    end_date: orderDetails.end_date || new Date().toISOString().substr(0, 10),
});

I had the partial reloads partially working. It reloaded part of the page but not the dates. the only problem is that it didn't update the table either.

Ben Taylor's avatar

@flourgirl this is how I do it.

import { router } from '@inertiajs/vue3'

router.get('/', { 
        only: ['orderDetails'], 
        ...selectedDates
    }, {
        preserveState: true
    })
flourgirl's avatar

@Ben Taylor If I add preserveState: true the table won't load. I can manually reset the page to make them load, but the dates reset. If I remove preservestate: true - the table loads but the dates reset.

Ben Taylor's avatar
Level 35

@flourgirl what happens if you get rid of

const orderDetails = ref(props.orderDetails)

And do

<tr v-for="order in $page.props.orderDetails"
flourgirl's avatar

@Ben Taylor It WORKS! Thank you soooo much. I've been struggling for longer than I wish to admit.

But now my filter doesn't work. I had the filter working using v-for order in filteredOrderDetails

function updateSelectedFilter(filter) {
  selectedFilter.value = filter;
}
const orderDetails = ref(props.orderDetails); //if I delete this line the page breaks
const filteredOrderDetails = computed(() => {
  const filterValue = selectedFilter.value;
  console.log(filterValue);
  if (filterValue === 'all') {
    return props.orderDetails;
  } else {
    return props.orderDetails.filter((order) => {
      if (filterValue === '0') {
        return order.order.order_status === 0;
      } else if (filterValue === '1') {
        return order.order.order_status === 1;
      } else if (filterValue === '2') {
        return order.order.order_status === 2;
      } else if (filterValue === '3') {
        return order.order.order_status === 3;
      }
      return false;
    });
  }
});

Suggestions? other than using a Laravel solution?

Ben Taylor's avatar

I use a watcher on my filters like this

watch(donated_at, throttle((value: Array<Date|null>) => {
    refreshList()
}, 300))

const refreshList = () => {
    router.get(route('donation.index'), { 
        only: ['donations'], 
        donated_at_from: donated_at?.value?.[0] ? formatDateForUrl(donated_at.value[0]) : '',
        donated_at_to: donated_at?.value?.[1] ? formatDateForUrl(donated_at.value[1]) : '',
        sort: sort.value, 
        sort_direction: sort_direction.value 
    }, {
        preserveState: true
    })
}

Please or to participate in this conversation.