It reply to the Bot - I'm trying to use Inertia - not Axios. Isn't there a way to do it with Inertia?
Jun 23, 2023
8
Level 1
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.
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"
Please or to participate in this conversation.